Published on

Hello World Programs in Different Languages

Authors

This post will demonstrate running hello world programs in different languages and also providing return time statistics

C++

Code

#include <iostream>
using namespace std;

int main()
{
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Compile:

$ c++ hello_cpp.cpp -o hello_cpp

Run:

$ time ./hello_cpp
Hello, World!

real	0m0.005s
user	0m0.001s
sys	  0m0.001s

Golang:

Code

package main

import "fmt"

func main() {
  fmt.Println("Hello, World!")
}

Compile:

$ go build hello_golang.go

Run:

time ./hello_golang
Hello, World!

real	0m0.006s
user	0m0.001s
sys	  0m0.003s

Python

Code:

#!/usr/bin/env python
print("Hello, World!")

Make it executable:

$ chmod +x ./hello_python.py

Run:

$ time ./hello_python.py
Hello, World!

real	0m0.033s
user	0m0.015s
sys	  0m0.010s

Ruby

Code:

#!/usr/bin/env ruby
puts "Hello, World!"

Make it executable:

$ chmod +x ./hello_ruby.rb

Run:

$ time ./hello_ruby.rb
Hello, World!

real	0m0.136s
user	0m0.080s
sys	  0m0.024s

Java

Code:

public class hello_java {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Compile:

$ javac hello_java.java

Run:

$ time java hello_java
Hello, World!

real	0m0.114s
user	0m0.086s
sys	  0m0.023s

Resource: