Scala is object oriented and functional programming language which is created by Martin Odersky and it was first released in 2003.
Scala is known due to development productivity, applications scalability and overall reliability.
Scala and Java have common runtime platform and most of feature of java are extended in scala.
Scala is compiled into Java Byte Code which is executed by the Java Virtual Machine (JVM). The scala command is similar to the java command, in that it executes your compiled Scala code.
There are two ways to writing scala programming which are as follows:
- Interactive Mode Programming
- Script Mode Programming
Interactive Mode Programming:
Open command prompt and type “scala” , this return following
Type the below text to the right of the Scala prompt and press the Enter key:
This will produce the following result:
Script Mode Programming:
Create a scala file name as “ScalaProgram.scala” .
Followings are compile and run program steps:
- Open notepad and add the code as above.
- Save the file as: ScalaProgram.scala.
- Open a command prompt window and go o the directory where you saved the program file. Assume it is C:\>
- Type ‘scalac ScalaProgram.scala’ and press enter to compile your code. If there are no errors in your code the command prompt will take you to the next line.
- Above command will generate a few class files in the current directory. One of them will be called class. This is a bytecode which will run on Java Virtual Machine (JVM).
- Now, type ‘scala ScalaProgram’ to run your program.
- You will be able to see ‘This is my first scala program’ printed on the window.