Hello world from different Programing languages

7 minute read

Published:

Here you’ll see different helloworld programs.

Programming Languages Table

Here is a little information about programming languages.

AñoLenguajeCreadorAplicacion
 Machine Code  
1679Binary CodeGottfried LeibnizProcesar Instrucciones y Codigos de texto (ASCII)
1950Assembler Hardware Manipulation
1957FORTRANJohn W. BackusScientific Computing
1958LispJohn P. McCarthy 
1972ProLogAlain A. Colmerauer 
1972CDennis M. RitchieAll is possible
1978SQLDonald D. ChamberlinDatabase Management System
1980C++Bjarne StroustrupLinux Applications
1982Common LispGuy L. Steele 
1984MJhon W. EatonSimulation and Numerical Analysis
1984VerilogPhil MoorbyHardware Design, Structure and Description
1987PerlLarry WallIntegrate services as unique admin system, processing text
1989BashBrian FoxCommand Line Interface language
1991PythonGuido van RossumArtificial Intelligence, Image Processing, Computer Vision
1993Ruby松本行弘 
1993RRobert C. GentlemanStatistical Analysis, Data analysis and Data Mining
1993JavaScriptBrendan EichClient Side Languag in Web Services
1995PhPRasmus LerdorfServer Side Language in Web Services
1995JavaJames A. GoslingAplicaciones Android OS
2001C#Anders HejlsbergWindows Applications
2009GoRobert PikeAll is possible

Bash

The name is Bourne-again shell, created by Brian Fox.

  • The Hello World program:

    #!/usr/bin/env bash
    
    #source "";
    
    main() {
      printf "\n\tHola Mundo Bash !!\n\n";
      printf "Numero de argumentos: %i\n" "$(($#+1))";
      for((c=0; c<=("$#"); c++)); do  
        printf "Argumento[$c] = ${!c} \n";
      done
      return ;
    }
    
    main $@;
    
  • To run the file:

    bash helloWorld.sh
    

C

This is the core of all applications, created by Dennis M. Ritchie.

  • To install:

    sudo apt-get install build-essentials
    
  • The Hello World program:

    #include <stdio.h>
    
    int main(int argc,char* argv[]){
      int i;
      printf("\n\tHola Mundo C !!\n\n");
      printf("Numero de argumentos: %i\n",argc);
      for(i=0;i<argc;i++){
        printf("Argumento[%i] = %s\n",i,argv[i]);
      }
      return 0;
    }
    
  • To run the file:

    gcc helloWorld.c -o helloWorld  && ./helloWorld
    

Converting to assembly

  • Preprocessing (EXPAND MACROS):

    cpp archivo.c > archivo.i
    
  • Compilation (FROM SOURCE CODE TO ASSEMBLY):

    gcc -Wall -S hello.i
    
  • Assembly (FROM ASEEMBLY LANGUAGE TO MACHINE CODE):

    as hello.s -o hello.o
    
  • Linking (CREATE THE FINAL EXECUTABLE):

    gcc hello.o
    

CPP (C++)

This is the core of all applications, created by Bjarne Stroustrup.

  • To install:

    sudo apt-get install build-essentials
    
  • The Hello World program:

    #include <iostream>
    
    using namespace std;
    
    int main(int argc,char* argv[]){
      int i;
      cout<<endl<<"\tHola Mundo C++ !!"<<endl<<endl;
      cout<<"Numero de argumentos: "<<argc<<endl;
      for(i=0;i<argc;i++){
        cout<<"Argumento["<<i<<"] = "<<argv[i]<<endl;
      }
      return 0;
    }
    
  • To run the file:

    g++ helloWorld.c++ -o helloWorld && ./helloWorld
    

CS (C#)

Created by Anders Hejlsberg.

  • To install:

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
    echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
    sudo apt install mono-devel
    
  • The Hello World program:

    using System;
    
    namespace HelloWorld{
      public class mainClass{
        public static void Main(string[] args){
          int argc = args.Length;
          string currentFile = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName();
          System.Console.WriteLine("\n\tHola Mundo C# !!\n");
          System.Console.WriteLine("Numero de argumentos: {0}", argc+1);
          System.Console.WriteLine("Argumento[0] = {0}", currentFile);
          for (int i = 0; i < argc; i++){
            System.Console.WriteLine("Argumento[{0}] = {1}", i+1, args[i]);
          }
        }
      }
    }
    
  • To run the file:

    mcs helloWorld.cs -out:helloWorld && ./helloWorld
    

Golang (Go)

This is the new core for a lot of applications, created by Robert Pike.

  • To install:

    • To install go latest:

      wget https://storage.googleapis.com/golang/go1.9.1.linux-amd64.tar.gz
      
    • Unzip in /usr/local directory:

      sudo tar -C /usr/local -xzf go1.9.1.linux-amd64.tar.gz
      tar -C ./ -xzf go1.9.1.linux-amd64.tar.gz
      
    • Then, modify /etc/profile file, add this line:

      export PATH=$PATH:/usr/local/go/bin
      
    • Also, add these lines in /home/$USER/.profile file:

      export GOPATH=$HOME/golangProjects
      export GOROOT=$HOME/go
      export PATH=$PATH:$GOROOT/bin
      
    • Finally, reboot or execute this:

      source .profile
      sudo source /etc/profile
      
  • The Hello World program:

    package main
    
    import (
      "os";
      "fmt";
    )
    
    func main() {
      fmt.Printf("\n\tHola Mundo Go !!\n\n");
      fmt.Printf("Numero de argumentos: %d\n", len(os.Args));
      for i,e := range os.Args {
        fmt.Printf("Argumento[%d] = %s\n", i, e);
      }
      return ;
    }
    
  • To run the file:

    go build -o helloWorld helloWorld.go && ./helloWorld
    

Java

Its a one important programming language in software development, created by James A. Gosling.

  • To install:

    sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update
    sudo apt-get install oracle-java8-installer
    sudo apt-get install oracle-java8-set-default
    
  • The Hello World program:

    class HelloWorld {
      public static void main(String[] args) {
        int argc = args.length;
        System.out.println("\n\tHola Mundo Java !!\n");
        System.out.printf("Numero de argumentos: %d\n", argc+1);
        System.out.printf("Argumento[0] = %s\n", "nombre del archivo");
        for(int i =0; i<argc; i++) {
          System.out.printf("Argumento[%d] = %s\n", i+1, args[i]);
        }
      }
    }
    
  • To run the file:

    javac helloWorld.java
    java HelloWorld
    

JavaScript (JS)

Another important programming language, created by Brendan Eich.

  • To install (also, you can run in web browser):

    curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
    nano nodesource_setup.sh
    sudo bash nodesource_setup.sh
    sudo apt-get install nodejs npm
    npm install [package]
    
  • The Hello World program:

    #!/usr/bin/env nodejs
    
    var path = require('path');
    
    function main(argv){
      var argc = argv.length;
      console.log('\n\tHola Mundo Javascript !!\n');
      console.log(`Numero de argumentos: ${(argv.length-1)}`);
      console.log('Argumento[0] = ' + path.basename(argv[1]))
      for (i=2; i< argc; i++){
        console.log(`Argumento[${i-1}] = ${argv[i]}`);
      }
      return;
    }
    
    main(process.argv)
    
  • To run the file:

    nodejs helloWorld.js
    

M (Octave/MATLAB)

An important programming languages to many applications in numeric fields, created by Jhon W. Eaton.

  • To install:

    sudo apt-get install octave liboctave-dev
    
  • The Hello World program:

    #!/usr/bin/env octave
    
    #pkg install control-1.0.0.tar.gz
    #pkg install control
    #pkg load control
    #addpath(genpath('./../locallib'));
    
    a=3;
    
    function []=main(argcs,argvs)
      printf("\n\tHola Mundo M !!\n\n");
      printf("Numero de argumentos: %i\n",argcs+1);
      printf("Argumento[0] = %s\n",program_name());
      for i = 1:argcs
        printf("Argumento[%i] = %s\n",i,argvs{i});
      end
      return;
    end
    
    main(nargin(),argv())
    
  • To run the file:

    octave helloWorld.m
    

Perl (PL)

Important language to develop http servers, created by Larry Wall.

  • To install:

    sudo apt-get install perl
    
  • The Hello World program:

    #!/usr/bin/env perl
    
    use strict;
    use warnings;
    
    sub main{
      my @argv = @_;
      my $argc = (@argv);
      print("\n\tHola Mundo Perl !!\n\n");
      print("Numero de argumentos: ".($argc+1)."\n");
      print("Argumento[0] = $0\n");
      foreach my $i(0..($argc-1)){
        print("Argumento[".($i+1)."] = $argv[$i]\n");
      }
      return;
    }
    
    main(@ARGV);
    
  • To run the file:

    perl helloWorld.pl
    

PHP

Important language to develop web servers, created by Rasmus Lerdorf.

  • To install:

    sudo apt-get install php7.0 composer
    composer install [package]
    
  • The Hello World program:

    #!/usr/bin/env php
    
    <?php
    class HelloWorld{
      public static function main($arguments, $count){
        print("\tHola Mundo PHP !!\n\n");
        print("Numero de argumentos: $count\n");
        foreach($arguments as $key => $value){
          print("Argumento[$key] = $value\n");
        }
        return;
      }
    }
    HelloWorld::main($argv, $argc);
    ?>
    
  • To run the file:

    php helloWorld.php
    

Python

A very important programming language, created by Guido van Rossum.

  • To install:

    sudo apt-get install python python-pip
    pip install [package]
    
  • The Hello World program:

    #!/usr/bin/env python
    
    # -*- coding: utf-8 -*-
      
    #from locallib import *
    import sys
    
    def main(argv):
      print("\n\tHola Mundo Python !!\n");
      argc = len(sys.argv);
      print("Numero de argumentos: %i" %(argc));
      for i in range(argc):
        print("Argumento[%i] = %s" %(i,sys.argv[i]));
      return;
    
    if __name__ == "__main__":
      main(sys.argv[1:]);
    
  • To run the file:

    python helloWorld.py
    

R

An important statistic language, created by Robert C. Gentleman.

  • To install:

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
    sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'
    sudo apt-get update
    sudo apt-get install r-base r-base-dev
    
  • The Hello World program:

    #!/usr/bin/env Rscript
    
    #library(stats);
    
    printf <- function(...){ invisible(cat(sprintf(...)))}
    
    main<-function(argsv){
      printf("\n\tHola Mundo R !!\n\n");
      argc<-length(argsv);
      argsv[4] = strsplit(argsv[4],"--file=")[[1]][2]
      if(argc>5){ printf("Numero de argumentos: %d\n",argc-4);}
      else{ printf("Numero de argumentos:",argc-3,"\n");}
      printf("Argumento[0] = %s\n",argsv[4]);
      if(argc>5){
        for(i in 6:argc){
          printf("Argumento[%d] = %s \n",i-5, argsv[i])
        }
      }
      return ();
    }
    
    mainf<-main(commandArgs(trailingOnly = FALSE));
    
  • To run the file:

    Rscript helloWorld.R
    

Ruby

Important to develop services, created by Yukihiro “Matz” Matsumoto.

  • To install:

    sudo apt-get install ruby-full ruby-dev ruby gem
    gem install [package]
    
  • The Hello World program:

#!/usr/bin/env ruby

#require 'io/console';

def main(argv)
  argc = argv.length;
  print("\n\tHola Mundo Ruby !!\n\n");
  print("Numero de argumentos: #{argc+1}\n");
  print("Argumento[0] = #{File.basename(__FILE__)}\n");
  for i in 0...argc
    print("Argumento[#{i+1}] = #{argv[i]}\n");
  end
  return;
end

main ARGV;
  • To run the file:

    ruby helloWorld.rb