javavariablesconstantsterminologyfinal

What is the difference between constant variables and final variables in java?


Please help me understand the difference between constant variables and final variables in Java. I am a bit confused with it.


Solution

  • Constant is the concept, the property of the variable.

    final is the java keyword to declare a constant variable.


    As other people pointed out, from a semantic/linguistic point of view the expression constant variable is an oxymoron and, as such, we could argue about its correctness.

    Quoting the specification, anyway, we can read

    A variable of primitive type [...], that is final and initialized with a compile-time constant expression (§15.28), is called a constant variable.

    I suppose, hence, that we can accept (and consider correct) this binomial for our purpose.