Hello World!
I decided to write the age old Hello World program in a lot of languages that interest me. 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: Ruby: Python: C: C++: Groovy: Clojure:
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.
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();
}
}
class HelloWorld
def initialize(name)
@name = name.capitalize
end
def sayHi
puts "Hello #{@name}!"
end
end
hello = HelloWorld.new("World")
hello.sayHi
class Hello:
def __init__(self, name):
self.name = name
def sayHi(self):
print "Hello " + str( self.name ) + "!"
hello = Hello("World")
hello.sayHi()
#include
main()
{
printf("Hello World!\n");
}
#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();
}
class Hello {
String name
void sayHi(){
println "Hello " + name + "!"
}
static void main(args){
def hello = new Hello(name:"World")
hello.sayHi()
}
}
(println "Hello World!")
(System/exit 0)