Define a constant value and use it : Constant « Language « Java Tutorial






  1. Using the final keyword to declare a variable.
  2. The final keyword specifies that the value of a variable is final and cannot be changed.
  3. It is a convention in Java to write constants in uppercase letters.
public class MainClass {

  public static void main(String[] arg) {
    final int FEET_PER_YARD = 3;          // Constant values
    final double MM_PER_INCH = 25.4;      // that cannot be changed

    System.out.println(FEET_PER_YARD);
    System.out.println(MM_PER_INCH);
    
  }

}
3
25.4








1.6.Constant
1.6.1.Define constant
1.6.2.Define a constant value and use it