Scalable java – Scala

Hello World in java:

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

Hello World in scala:

object HelloWorld{
 def main(args: Array[String]){
 	println("Hello World!")
 }
}

Into the details(decompiled form):Java:

import java.io.PrintStream;

public class HelloWorld
{

    public HelloWorld()
    {
    }

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

Scala:

public final class HelloWorld
{

    public static final int $tag()
    {
        return HelloWorld$.MODULE$.$tag();
    }

    public static final void main(String args[])
    {
        HelloWorld$.MODULE$.main(args);
    }
}
//--------------------------------------
import scala.Predef$;
import scala.ScalaObject;

public final class HelloWorld$
    implements ScalaObject
{

    public HelloWorld$()
    {
    }

    public void main(String args[])
    {
        Predef$.MODULE$.println("Hello World!");
    }

    public int $tag()
    {
        return scala.ScalaObject.class.$tag(this);
    }

    public static final HelloWorld$ MODULE$ = this;

    static
    {
        new HelloWorld$();
    }
}

Seems like there’s more stuff for a simple example like this.
But the language seems quite cool.
Several powerful factors includes:

  • compiling to java bytecode(as you can see from above, meaning that it runs on the JVM (hmm… its quite interesting that it is said to be scalable when its running on JVM, but anyhow, gotta explore further)
  • functional language, yet borrows ideas from OO (definitely a very attractive feature)

I’m still quite new to the language but probably I will compare (syntax-wise) java with scala when I’m doing slides for my java tutorial class 🙂

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to FurlAdd to Newsvine