How do I write constants names in Java?


While writing the name of the constants it is suggested to

  • write all the letters in upper case.
  • If constant contains more than one word they should be separated by underscore (_).

Example

Live Demo

public class ConstantsTest {
   public static final int MIN_VALUE = 22;
   public static final int MAX_VALUE = 222;
   public static void main(String args[]) {
      System.out.println("Value of the constant MIN_VALUE: "+MIN_VALUE);
      System.out.println("Value of the constant MAX_VALUE: "+MAX_VALUE);
   }
}

Output

Value of the constant MIN_VALUE: 22
Value of the constant MAX_VALUE: 222

Updated on: 30-Jul-2019

534 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements