“Hello, world!”s collection

Hello, world!

A collection of “Hello, world!”s which I have managed to collect on my travels through the universe of computer programming… Utterly pointless, yet still a rather good exercise in comparing programming languages.

(More are coming, but I don’t know when…)


Java

Probably the first ever Hello world I wrote:

public class HelloWorld {

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

}

(This must be saved in a file called HelloWorld.java to compile.)


GNU C

An artifact left over from evil times… However it can be rather useful.

#import <stdio.h>

int main (void)

{
    puts ("Hello, world!");
    return 0;
}

It is also possible to use printf (String) instead of puts, which seems to be the default method for most people, but it is also more inefficient.


C++

Yet another horrible language, that somehow became important…

#include <iostream>

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

Supposedly this is a non standards-compliant method to print a newline character — the other method of doing it is simply adding “\n” at the end of the string. However this is a method used by many, and compiles and works fine with g++, and has been proposed to be added to the standard. Choose your own way.


Python

Supposedly the future of the internet, to become what php is today.

#!/usr/bin/python
print "Hello, world!"

Nice and clean. The shebang line isn’t strictly necessary. Only one line of actual python code does all the work.

Here is another python example, this time wrapped as part of a class. The constructor sets an internal variable storing the sing to be shown, the hi() method prints it: (the last line simply creates an instance of HelloWorld and calls the hi() method on it)

#!/usr/bin/python
class HelloWorld:
    def __init__(self):
        self.string = "Hello, world!"
    def hi(self):
        print(self.string)

HelloWorld().hi()

  1. No comments yet.

  1. No trackbacks yet.