Create, Compile and Run the Hello World Program in Scala
A school fair needs a welcome screen at the entrance. Print a greeting first. Seeing the exact words on screen confirms that the saved program ran and sent text to its output.
1. Save the following program as HelloWorld.scala.
A Scala source file can have a different name from the object it defines.
object HelloWorld {
def main(args: Array[String]) = {
println("Hello world")
}
}
Hello world
2. With Scala CLI, run scala run HelloWorld.scala. With the classic Scala 2 distribution shown below, use scalac HelloWorld.scala followed by scala HelloWorld.
