How to “Hellow World” in different programming languages

Programming Languages Table

Here is a little information about programming languages.

Table 1

Bash

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

  • The Hello World in Bash:
#!/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 $@;
  • How to run the file:

C

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

  • To install:
  • The Hello World in C:
#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;
}
  • How to compile & run the file:

Converting to assembly

  • Preprocessing (EXPAND MACROS):
  • The compilation (FROM SOURCE CODE TO ASSEMBLY):
  • Assembly (FROM ASSEMBLY LANGUAGE TO MACHINE CODE):
  • Linking (CREATE THE FINAL EXECUTABLE):

CPP (C++)

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

  • To install:
  • The Hello World in C++:
#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;
}
  • How to compile & run the file:

CS (C#)

Created by Anders Hejlsberg.

  • To install:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EFecho "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.listsudo apt install mono-devel
  • The Hello World in C#:
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]);
}
}
}
}
  • How to compile & run the file:

Golang (Go)

This is the new core for many applications, created by Robert Pike.

  • 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:
  • 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
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 ;
}

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 in Java:
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 was created by Brendan Eich.

  • To install (also, you can run it in a web browser):
curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.shnano nodesource_setup.shsudo bash nodesource_setup.shsudo apt-get install nodejs npmnpm 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:

M (Octave/MATLAB)

An important programming language for many applications in numeric fields, created by Jhon W. Eaton.

  • To install:
  • The Hello World in Octave:
#!/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:

Perl (PL)

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

  • To install:
  • The Hello World in Perl:
#!/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:

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 in PHP:
#!/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 in Python:
#!/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:

R

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

  • To install:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'sudo apt-get updatesudo apt-get install r-base r-base-dev
  • The Hello World in R:
#!/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:

Ruby

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

  • To install:
sudo apt-get install ruby-full ruby-dev ruby gemgem install [package]
  • The Hello World in Ruby:
#!/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:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store