Hello World!

I decided to write the age old Hello World program in a lot of languages that interest me.
I didn’t get around to objective-c or c#.
If the language was object oriented, I tried to write an OO Hello World example.

I enjoyed doing this, and I hope to post some more complex programs implemented in all these languages.

So here’s what I came up with.

Java:


public class Hello{
    private String name;
    public Hello(String name){
        this.name = name;
    }
    public void sayHi(){
        System.out.println("Hello " + name + "!");
    }
    public static void main(String[] args){
        Hello hello = new Hello("World");
        hello.sayHi();
    }
}

Ruby:


class HelloWorld
   def initialize(name)
      @name = name.capitalize
   end
   def sayHi
      puts "Hello #{@name}!"
   end
end

hello = HelloWorld.new("World")
hello.sayHi

Python:


class Hello:
   def __init__(self, name):
      self.name = name
   def sayHi(self):
      print "Hello " + str( self.name ) + "!"

hello = Hello("World")
hello.sayHi()

C:


#include
main()
{
   printf("Hello World!\n");
}

C++:


#include
#include

using namespace std;

class HelloClass
{
   private:
      string name;
   public:
      HelloClass(string inName)
      {
         name = inName;
      }
      void sayHi()
      {
         cout << "Hello " << name << "!" << endl;
      }
   };

int main()
{
   HelloClass("World").sayHi();
}

Groovy:


class Hello {
   String name
   void sayHi(){
      println "Hello " + name + "!"
   }

   static void main(args){
      def hello = new Hello(name:"World")
      hello.sayHi()
   }
}

Clojure:


(println "Hello World!")
(System/exit 0)