Difference between var and val in spark- Interview question

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
  • User AvatarANKUSH THAVALI
  • 11 Jun, 2019
  • 0 Comments
  • 25 Secs Read

Difference between var and val in spark- Interview question

Var keyword is just similar to variable declaration in Java whereas Val is little 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 java final keyword.

Val refers to immutable declaration of a variable whereas var refers to mutable declaration of a variable in Scala.

Val and var are the two keywords used to define variables in Scala.