How do I declare a constant in Java E-mail
User Rating:Java Tips  How do I declare a constant in JavaJava Tips  How do I declare a constant in JavaJava Tips  How do I declare a constant in JavaJava Tips  How do I declare a constant in JavaJava Tips  How do I declare a constant in Java/140

PoorBest

Java does not directly support constants. However, a static final variable is effectively a constant.

The static modifier causes the variable to be available without loading an instance of the class where it is defined. The final modifier causes the variable to be unchangeable.

Java constants are normally declared in ALL CAPS. Words in Java constants are normally separated by underscores.

An example of constant declaration in Java is written below:


publicclassMaxUnits{

publicstaticfinalintMAX_UNITS=25;

}