Basics of Scala

3 / 4

Scala - Basic Program

A basic program looks like below:

object Hello {
   /* This is my first java program.  
   * This will print 'Hello There' as the output
   */
   def main(args: Array[String]) {
      println("Hello There!") // prints Hello World
   }
}

Save above example in a file named Hello.scala or any other file. The convention is to keep the file name same as the main object name suffixed with '.scala'. Compile and run this as below. Scala binary class files are generated when the program is compiled.
To compile: scalac <MainClass.scala>
To run, scala <MainClass>

$ scalac Hello.scala
$ scala Hello
Hello There!
$ ls -ltrh *Hello*
-rw-r--r-- 1 manoj manoj 236 Oct  8 19:22  Hello.scala
-rw-r--r-- 1 manoj manoj 655 Oct  8 19:22 'Hello$.class'
-rw-r--r-- 1 manoj manoj 614 Oct  8 19:22  Hello.class
$

No hints are availble for this assesment

Answer is not availble for this assesment

Loading comments...