Scala stands for Scalable language.
Scala is a high-level, multi-paradigm programming language. It is a pure object-oriented programming language which also provides support to the functional programming approach. Scala programs can convert to bytecodes and run on the JVM (Java Virtual Machine).
Following are the key features of Scala:
● Scala is object-oriented programming language
● Scala is functional language
● Scala is statically typed
● Scala runs on the JVM
● Scala can execute Java code
● Scala can do Concurrent & Synchronize processing
Scala does not expect to provide redundant type information i.e. there is no need to specify a type in most of the cases.
Scala is being used everywhere and importantly in enterprise web applications. Some of the popular Scala Web Frameworks are:
● The Lift Framework
● The Play framework
● The Bowler framework
A closure is a function, whose return value depends on the value of one or more variables declared outside this function.
A trait encapsulates method and field definitions, which can then be reused by mixing them into classes. Traits are used to define object types by specifying the signature of the supported methods.
Scala program can be executed in two different modes:
● Interactive mode
● Script mode
The'scalac' command is used to compile the Scala program and it will generate a class file which then can be run on Java Virtual Machine (JVM) using 'scala' command. Below is the sample:
\> scalac HelloWorld.scala \> scala HelloWorld
The '$' character is a reserved keyword in Scala and should not be used in identifiers. So $age is illegal identifier in Scala.
In Scala Unit data type corresponds to no value.
In Scala mutable variables are the variables that can change value. These mutable variables should be declared using the keyword var. Below is the syntax:
\>var myVar : String = "abc"
In Scala immutable variables are the variables that cannot change value. These immutable variables should be declared using the keyword val. Below is the syntax:
\>val myVar : String = "abc"
Following are the different scopes of variables in Scala:
● Method Parameters
● Local Variables
In Scala fields are variables that belong to an object. The fields are accessible from inside every method in the object. It can also be accessible outside the object depending on what access modifiers are used to declare fields.