Scala main

Scala has a simple way of creating a ‘main’ method:

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

This will compile down to the “public static void main” that Java uses.

Alternately, you can extend “App”:

object HelloWorld extends App {
  println("Hello World")
}

Note that the “main” part is done for you.

Also you must compile this, and not run it through the interpreter. I.e.:

scalac hello.scala
scala Hello
Hello World!

Leave a Reply

Your email address will not be published. Required fields are marked *