Open notepad and add the following code to it.
Example
object HelloWorld {
/* This is my first java program.
* This will print 'Hello World' as the output
*/
def main(args: Array[String]) {
println("Hello, world!") // prints Hello World
}
}
Save the file as − HelloWorld.scala.
Open the command prompt window and go to the directory where the program file is saved. The ‘scalac’ command is used to compile the Scala program and it will generate a few class files in the current directory. One of them will be called HelloWorld.class. This is a bytecode that will run on Java Virtual Machine (JVM) using the ‘scala’ command.
Use the following command to compile and execute your Scala program.
\> scalac HelloWorld.scala
\> scala HelloWorld
Output
Hello, World!