Differentiate between Val and var in Scala.

bookmark

Val and var are the two keywords used to define Scala variables. Var keyword is similar to a variable declaration in Java, whereas Val is slightly different. Once a variable is declared using Val the reference cannot be changed to point to another reference. This functionality of Val keyword in Scala can be related to the functionality of the Java final keyword. To simplify it, Val refers to the immutable declaration of a variable, whereas var refers to the mutable declaration of a variable in Scala.