TheLostMind February 2016
A constant is value that cannot be changed. For example
Lets consider Java :
int i = 5; // Here 5 is constant but the reference (i) can change and point to 6. i.e, the value 5 is immutable, but the reference (i) is mutable.
final keyword to the above statement :
final int i = 5; // Here the keyword final ensures that the reference cannot point to any other value.
i becomes a compile time constant and its value is passed in the byte-code itself.
Note that a reference could point to a constant value (
immutable object ) or a
Technically speaking, immutable values aren't same as constants in case of reference types (except String).