In fact, in Java, the term constant does not have a specific meaning. This occurs in JLS only in a broader expression, an expression for the compile time constant , which is an expression that can (and should be) computed, and not at run time. (And the const keyword is reserved to allow compilers to give more efficient error messages.)
Instead, in Java, we use the term final to refer to variables (whether cool, object, or local) that cannot be changed and are immutable when we refer to objects that cannot change. Both can be used when it comes to the variable x - the first means that the variable itself (which means that it cannot be switched to another object), the second means the object behind the variable. Thus, here the two values are orthogonal and are often combined to create a “true constant”.
Paŭlo Ebermann
source share