Hello World Scala

For this you need an IDE that supports Scala – I suggest getting the eclipse bundle from here: http://scala-ide.org/download/sdk.html

In a new or existing Scala Project create a new class called com.vff.HelloWorld – paste or type the following inside:

package com.vff

object HelloWorld extends App {
println("Hello, World!")

and now run this Scala class – in eclipse that means right-click, choose ‘Run As’ and then Scala Application from the available options. You should get ‘Hello, World!’ printed out in the console.

There are a few things of interest here. The use of ‘object’ for a class definition, the extending of ‘App’ and the simple ‘println’. Here goes..
‘object’ defines a class but defines it as a Singleton. only one instance will be created – it’s worth checking out Singleton if you don’t know it, basically one instance of this type is generated, no more instances can be created – a java equivalent might be a util class – all static methods. App is an existing scala type, extending it makes our class runnable. – like adding a big ‘public static void main(String[] args)’ around its contents. println is like a shortcut to System.out.println – nice and terse.


One thought on “Hello World Scala

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s