Skip to content
 
 

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hello World Journey

Be part of the journey and get started exploring Programming languages, source code, tools, cloud,...

Getting Started

In this repository, you'll find scripts, source code files to build Hello World applications in different Programming Languages.

Some Hello World applications will be deployed in the cloud.

This chapter describes how to :

  1. Install the pre-requisites including Visual Studio Code, Dev Container
  2. Install the tools associated with each Programming Language
  3. Build and run the Hello World applications

This repository contains the following resources :

  • A Dev container under '.devcontainer' folder
  • The source code of the Hello World applications in different languages under 'src' folder

Installing the pre-requisites

In order to test the solution, you need first an Azure Subscription, you can get further information about Azure Subscription here.

You also need to install Git client and Visual Studio Code on your machine, below the links.

Windows Linux MacOS
Git Client for Windows Git client for Linux Git Client for MacOs
Visual Studio Code for Windows Visual Studio Code for Linux   Visual Studio Code for MacOS    

Once the Git client is installed you can clone the repository on your machine running the following commands:

  1. Create a Git directory on your machine

        c:\> mkdir git
        c:\> cd git
        c:\git>
  2. Clone the repository.
    For instance:

        c:\git> git clone  https://github.com/flecoqui/HelloWorld.git 
        c:\git> cd ./HelloWorld
        c:\git\HelloWorld> 

Using Dev Container

Installing Dev Container pre-requisites

You need to install the following pre-requisite on your machine

  1. Install and configure Docker for your operating system.

    • Windows / macOS:

      1. Install Docker Desktop for Windows/Mac.

      2. Right-click on the Docker task bar item, select Settings / Preferences and update Resources > File Sharing with any locations your source code is kept. See tips and tricks for troubleshooting.

      3. If you are using WSL 2 on Windows, to enable the Windows WSL 2 back-end: Right-click on the Docker taskbar item and select Settings. Check Use the WSL 2 based engine and verify your distribution is enabled under Resources > WSL Integration.

    • Linux:

      1. Follow the official install instructions for Docker CE/EE for your distribution. If you are using Docker Compose, follow the Docker Compose directions as well.

      2. Add your user to the docker group by using a terminal to run: 'sudo usermod -aG docker $USER'

      3. Sign out and back in again so your changes take effect.

  2. Ensure Visual Studio Code is already installed.

  3. Install the Remote Development extension pack

Using Visual Studio Code and Dev Container

  1. Launch Visual Studio Code in the folder where you cloned the 'ps-data-foundation-imv' repository

        c:\git\HelloWorld> code .
  2. Once Visual Studio Code is launched, you should see the following dialog box:

    Visual Studio Code

  3. Click on the button 'Reopen in Container'

  4. Visual Studio Code opens the Dev Container. If it's the first time you open the project in container mode, it first builds the container, it can take several minutes to build the new container.

  5. Once the container is loaded, you can open a new terminal (Terminal -> New Terminal).

  6. And from the terminal, you have access to the tools installed in the Dev Container like az client,....

        vscode ➜ /workspace/HelloWorld $ az login 

Programming Languages Overview

The subsequent chapters describe how to write basic applications in different programming language. For each language, a bash file (Linux) or a command file (Windows) is available to install the tools associated with the programming language on Linux or Windows.

  • ./src/[Programming Language Name]/install.cmd: Installation script on Windows
  • ./src/[Programming Language Name]/install.sh: Installation script on Linux

Moreover, for each language, a serie of samples is available and for each sample bash files called build.sh and run.sh are available to build and run the sample application.

C Programming Language

C Programming Language

Install C compilers and linkers

Install gcc on Windows

  1. Information about the GCC compiler on Windows available here: https://www.mingw-w64.org/

  2. Install MSYS2 on your machine Information: https://www.msys2.org/ Binaries: https://github.com/msys2/msys2-installer/releases/download/2024-05-07/msys2-x86_64-20240507.exe

  3. Install GCC in MSYS2 shell terminal:

    pacman -S mingw-w64-ucrt-x86_64-gcc
  1. Run GCC:
   gcc –version
   gcc.exe (Rev6, Built by MSYS2 project) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Install gcc on Linux

  1. Update packages list, install build-essential and documentation:
    $ sudo apt update
    $ sudo apt install build-essential
    $ sudo apt-get install manpages-dev
    $ gcc --version

Sample 1: Hello World

Source code: test.c

    #include "stdio.h"
    int main()
    {
        printf("Hello World\n");
    }

build command:

    gcc test.c  -o test.exe 

build command to optimize size:

    gcc test.c  -o testsmall.exe  -O2 -s

build command to generate assembly code:

    gcc -o test.asm  -S  test.c

assembly code with gcc running on Linux:

        .file	"test.c"
        .text
        .section	.rodata
    .LC0:
        .string	"Hello World"
        .text
        .globl	main
        .type	main, @function
    main:
    .LFB0:
        .cfi_startproc
        endbr64
        pushq	%rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq	%rsp, %rbp
        .cfi_def_cfa_register 6
        leaq	.LC0(%rip), %rax
        movq	%rax, %rdi
        call	puts@PLT
        movl	$0, %eax
        popq	%rbp
        .cfi_def_cfa 7, 8
        ret
        .cfi_endproc
    .LFE0:
        .size	main, .-main
        .ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
        .section	.note.GNU-stack,"",@progbits
        .section	.note.gnu.property,"a"
        .align 8
        .long	1f - 0f
        .long	4f - 1f
        .long	5
    0:
        .string	"GNU"
    1:
        .align 8
        .long	0xc0000002
        .long	3f - 2f
    2:
        .long	0x3
    3:
        .align 8
    4:

assembly code with gcc running on Windows:

        .file	"test.c"
        .text
        .def	__main;	.scl	2;	.type	32;	.endef
        .section .rdata,"dr"
    .LC0:
        .ascii "Hello World\0"
        .text
        .globl	main
        .def	main;	.scl	2;	.type	32;	.endef
        .seh_proc	main
    main:
                                                                                        
        .seh_pushreg	%rbp
        movq	%rsp, %rbp
        .seh_setframe	%rbp, 0
        subq	$32, %rsp
        .seh_stackalloc	32
        .seh_endprologue
        call	__main
        leaq	.LC0(%rip), %rax
        movq	%rax, %rcx
        call	puts
        movl	$0, %eax
        addq	$32, %rsp
        popq	%rbp
        ret
        .seh_endproc
        .ident	"GCC: (Rev6, Built by MSYS2 project) 13.2.0"
        .def	puts;	.scl	2;	.type	32;	.endef

Sample 2: Read input key

Source code: test.c

    #include "stdio.h"
    int main()
    {
        char ch;
        printf("How is the World? M: Mad, B: Beautiful \n");
        ch=fgetc(stdin);
        if(ch=='M'){
            printf("Hello Mad World!\n");
        }
        else if(ch=='B'){
            printf("Hello Beautiful World!\n");
        }
        else{
            printf("Hello World!\n");
        }
    }

build command:

    gcc test.c  -o test.exe 

Sample 3: Read input string (danger)

Source code: test.c

    #include "stdio.h"

    int main()
    {
        char str[3];
            char const *sunny = "sunny";
        printf("How is the World?\n");
        gets(str);
        printf("Hello %s and %s World!\n",str,sunny);
    }

build command:

    gcc test.c  -o test.exe 

Sample 4: Enter secure string

Source code: test.c

	#include "stdio.h"
	#define MAX_LIMIT 3
	int main()
	{
		char str[MAX_LIMIT];
		char const *sunny = "sunny";
		printf("How is the World?\n");
		fgets(str, MAX_LIMIT, stdin);
		printf("Hello %s and %s World!\n",str,sunny);
	}

build command:

    gcc test.c  -o test.exe 

Sample 5: Key Stroke Windows in while loop

Source code: test.c

    #include <stdio.h>
    #include <conio.h>
    int main()
    {
        printf("The World is running, press escape to exit\n");
        while (1) {
            if ( kbhit() ) {
                int ch;
                ch = getch();
                if (ch == 0x1B){
                    printf("ESC key pressed, exit\n");
                    break;
                }
                else
                    printf("Key pressed = '%c'\n",ch);
            }
        }
        return 0;
    }

build command:

    gcc test.c  -o test.exe 

Sample 6: Key Stroke Linux in while loop

Source code: test.c

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <termios.h>
    #include <ctype.h>
    #include <sys/ioctl.h>
    #include <unistd.h>
    int kbhit()
    {
        int byteswaiting;
        ioctl(STDIN_FILENO, FIONREAD, &byteswaiting);
        return byteswaiting;
    }
    int getch(void)
    {
        int ch;
        ch = getchar();
        return ch;
    }
    void enable_raw_mode()
    {
        struct termios term;
        tcgetattr(STDIN_FILENO, &term);
        term.c_lflag &= ~(ICANON | ECHO); // Disable echo as well
        tcsetattr(STDIN_FILENO, TCSANOW, &term);
    }
    void disable_raw_mode()
    {
        struct termios term;
        tcgetattr(STDIN_FILENO, &term);
        term.c_lflag |= ICANON | ECHO;
        tcsetattr(STDIN_FILENO, TCSANOW, &term);
    }
    int main()
    {
        char ch;
        printf("The World is running, press escape to exit\n");
        enable_raw_mode();
        while (1) {
            if ( kbhit() ) {
            ch = getch();
                if (ch == 0x1B){
                    printf("ESC key pressed, exit\n");
                    break;
                }
                else
                    printf("Key pressed = '%c'\n",ch);
            }
        }
        disable_raw_mode();
        return 0;
    }

build command:

    gcc test.c  -o test.exe 

Java Programming Language

Java Programming Language

Install Java SDK

Install Java SDK on Windows

  1. Download the JDK version 21 from there: https://www.oracle.com/java/technologies/downloads/#jdk21-windows
  2. Follow the steps to install the JDK on your local machine

Install Java SDK on Linux

  1. Download the JDK version 21 running the following command in a terminal:
    sudo wget https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.deb
  1. Run the following command to install the JDK 21 on your machine running Linux
    sudo dpkg -i jdk-21_linux-x64_bin.deb

Sample 1: Hello World

Source code: test.java

    class Program
    { 
        public static void main(String []args) 
        { 
            System.out.println("Hello world"); 
        } 
    } 

build and run commands:

    javac -d bin test.java
    java test.java

Sample 2: Key String detection

Source code: test.java

    import java.util.Scanner; 

    class Program
    { 
        public static void main(String []args) 
        { 
            System.out.println("How is the World? M: Mad, B: Beautiful ");
            Scanner scanner = new Scanner(System.in);
            char ch = scanner.next().charAt(0);
            if(ch=='M'){
                System.out.println("Hello Mad World!\n");
            }
            else if(ch=='B'){
                System.out.println("Hello Beautiful World!\n");
            }
            else{
                System.out.println("Hello World!\n");
            }
        } 
    }  

build and run commands:

    javac -d bin test.java
    java test.java

Sample 3: Enter string

Source code: test.java

    import java.util.Scanner; 
    class Program
    { 
        public static void main(String []args) 
        { 
            String sunny = "sunny";
            System.out.println("How is the World?");
            Scanner scanner = new Scanner(System.in);
            String str = scanner.next();
            if (str == null || str.isEmpty() || str.trim().isEmpty()) 
                System.out.printf("Hello %s World!\n",sunny);
            else
                System.out.printf("Hello %s and %s World!\n", str, sunny);        
        } 
    } 

build and run commands:

    javac -d bin test.java
    java test.java

Sample 4: Key Stroke in while loop

Source code: test.java

    import java.util.Scanner; 
    class Program {
        public static void main(String []args) 
        {  
            System.out.printf("The World is running, press escape to exit?");
            while(true)
            {
                Scanner scanner = new Scanner(System.in);
                char ch = scanner.next().charAt(0);

                if(ch==27){
                    System.out.printf("ESC key pressed, exit\n");
                    break;
                }
                else
                    System.out.printf("Key pressed = %c", ch);
            }
        } 
    }

build and run commands:

    javac -d bin test.java
    java test.java

C# Programming Language

C# Programming Language

Install DotNet SDK

Install DotNet SDK on Windows

  1. Download dotnet v8 for Windows from https://dotnet.microsoft.com/en-us/download/dotnet/8.0
  2. Follow the steps to install DotNet SDK v8.0 on Windows

Install DotNet SDK on Linux

  1. Run the following commands to install DotNet SDK v8.0 on Linux
    sudo apt-get update 
    sudo apt-get install -y apt-transport-https 
    sudo apt-get install -y dotnet-sdk-8.0

Sample 1: Hello World

Source code: test.cs

    public class Program
    {
        public static void Main(string[] args)
        {
            System.Console.WriteLine("Hello World");
        }
    }

build and run commands:

    dotnet restore
    dotnet build
    dotnet run

Sample 2: Self Contained Binary

Source code: test.cs

    public class Program
    {
        public static void Main(string[] args)
        {
            System.Console.WriteLine("Hello World");
        }
    }

build and run commands on Linux:

    dotnet restore
    dotnet build --self-contained -r   linux-x64
    ./bin/Debug/net8.0/linux-x64/test

build and run commands on Windows:

    dotnet restore
    dotnet build --self-contained -r   win-x64
    ./bin/Debug/net8.0/win-x64/test.exe    

Sample 3: Key Stroke detection

Source code: test.cs

    public class Program
    {
        public static void Main(string[] args)
        {
            System.Console.WriteLine("How is the World? M: Mad, B: Beautiful ");
            while(!Console.KeyAvailable);
            System.ConsoleKey ch = Console.ReadKey(true).Key;
            if(ch==System.ConsoleKey.M){
                System.Console.WriteLine("Hello Mad World!\n");
            }
            else if(ch==System.ConsoleKey.B){
                System.Console.WriteLine("Hello Beautiful World!\n");
            }
            else{
                System.Console.WriteLine("Hello World!\n");
            }
        }
    }

build and run commands:

    dotnet restore
    dotnet build
    dotnet run

Sample 4: Enter string

Source code: test.cs

    public class Program
    {
        public static void Main(string[] args)
        {
            string sunny = "sunny";
            System.Console.WriteLine("How is the World?");
            string? str = Console.ReadLine();
            if(string.IsNullOrEmpty(str))
                System.Console.WriteLine($"Hello {sunny} World!");
            else
                System.Console.WriteLine($"Hello {str} and {sunny} World!");
        }
    }

build and run commands:

    dotnet restore
    dotnet build
    dotnet run

Sample 5: Key Stroke in while loop

Source code: test.cs

    public class Program
    {
        public static void Main(string[] args)
        {
            System.ConsoleKey ch; 
            System.Console.WriteLine("The World is running, press escape to exit?");
            while(true)
            {
                if(Console.KeyAvailable){
                    ch = Console.ReadKey(true).Key;
                    if(ch==System.ConsoleKey.Escape){
                        System.Console.WriteLine("ESC key pressed, exit");
                        break;
                    }
                    else
                        System.Console.WriteLine($"Key pressed = {ch} , exit");
                }
            }
        }
    }

build and run commands:

    dotnet restore
    dotnet build
    dotnet run

Python Programming Language

Python Programming Language

Install Python SDK 3.10

  1. Download Python SDK 3.10 for Windows from https://www.python.org/downloads/windows/
  2. Follow the steps to install Python SDK 3.10 on Windows

Install Python SDK 3.10 on Linux

  1. Run the following commands to install Python SDK v3.10 on Linux
    sudo apt update
    sudo apt install software-properties-common -y
    sudo add-apt-repository ppa:deadsnakes/ppa
    sudo apt update
    sudo apt install python3.10 python3.10-venv python3.10-dev
    python3 --version
    ls -la /usr/bin/python3
    sudo rm /usr/bin/python3
    sudo ln -s python3.10 /usr/bin/python3
    python3 --version
    curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
    python3 -m pip --version
    python3.10 -m pip install ipython
    python3.10 -m venv venv
    pip install ipython

Sample 1: Hello World

Source code: test.py

    print("Hello World")

Run command:

    python ./test.py

Sample 2: Key Stroke detection

Source code: test.py

    from getkey import getkey

    print("How is the World? M: Mad, B: Beautiful")
    key = getkey()
    if key == "M":
        print("Hello Mad World!")
    else:
        if key == "B":
            print("Hello Beautiful World!")
        else:
            print("Hello World!")

Run command:

    python ./test.py

Sample 3: Enter string

Source code: test.py

    sunny = "sunny"
    str = input("How is the World?\n")
    if not str.split(): 
        print(f"Hello {sunny} World!")
    else:
        print(f"Hello {str} and {sunny} World!")    

Run command:

    python ./test.py

Sample 4: Key Stroke in while loop

Source code: test.py

    from getkey import getkey

    print("The World is running, press escape to exit?")
    while True:
        key = getkey()
        if ord(key) == 27:
            print("ESC key pressed, exit!")
            break
        else:
            print(f"Key pressed = {key} ")

Build and Run command:

    pip install getkey
    python ./test.py

HTML/Javascript Programming Language

HTML Programming Language

Install Node.js

Node.js is used to run locally an http server which will serve the HTML and Javascript files.

Install Node.js on Windows

  1. Download Node.js for Windows from https://nodejs.org/en/download/package-manager
  2. Follow the steps to install Node.js on Windows

Install Node.js on Linux

  1. Run the following commands to install Node.js on Linux
    curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - 
    sudo apt-get install -y nodejs \
    sudo  npm install -g npm@latest 
    sudo npm install http-server -g

Sample 1: Hello World

Source code: index.html

    <!doctype html>
    <html lang="en">
    <body>
        <h1>Hello World</h1>
    </body>
    </html>

Run command:

    http-server .  -c-1

Sample 2: Key Stroke detection

Source code: index.html and index.js

    <!doctype html>
    <html lang="en">
    <body>
        <h1>How is the World (M: Mad, B: Beautiful)?</h1>
        <script src="index.js"></script>
    </body>
    </html>
    document.addEventListener("keypress", function(event) {
        if (event.key === "M") {
        alert('Hello Mad World!');
        }
        else if (event.key === "B") {
        alert('Hello Beautiful World!');
        }
        else{
            alert('Hello World!');
        }
    });

Run command:

    http-server .  -c-1

Sample 3: Enter string

Source code: index.html and index.js

    <!doctype html>
    <html lang="en">
    <body>
        <h1>How is the World (enter the adjective below)?</h1>
        <input name="status" type="text" maxlength="48" id="statusId" />
        <button id="statusButton">Ok</button>
        <script src="index.js"></script>
    </body>
    </html>
    button=document.getElementById("statusButton")

    button.addEventListener("click", function(event) {
        var status = document.getElementById("statusId").value;
        if (status && status.length > 0) {
        alert(`Hello ${status} World!`);
        }
        else {
        alert('Hello  World!');
        }
    });

Run command:

    http-server .  -c-1

Sample 4: Key Stroke in while loop

Source code: index.html and index.js

    <!doctype html>
    <html lang="en">
    <body>
        <h1>The World is running, press escape to exit</h1>
        <div>
            <div>
            <label name="status" type="text" maxlength="48" id="statusId" width="400px"></label>
            </div>
            <div>
            <label name="logs" type="text" maxlength="48" id="logId" width="400px"></label>
            </div>  
        </div>
        <script src="index.js"></script>
    </body>
    </html>
    document.addEventListener("DOMContentLoaded", function(e) {
    var statusCtl = document.getElementById("statusId")
    if (statusCtl){
        statusCtl.innerHTML = "Running"
    }
    });

    document.addEventListener("keydown", function(event) {
    if (event.key === "Escape") {
        var statusCtl = document.getElementById("statusId")
        if (statusCtl){
            statusCtl.innerHTML = "Not running"
        };
    }
    var logCtl = document.getElementById("logId");
    if (logCtl){
        logCtl.innerHTML = `Key ${event.key} pressed!`
    };
    });

Run command:

    http-server .  -c-1

About

Several Operating System, several Languages, Hello World

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages