How do I declare a constant in Java
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:
<font color="#7f0055">public class </font><font color="#000000">MaxSeconds </font><font color="#000000">{</font>
<font color="#ffffff"> </font><font color="#7f0055">public static final </font><font color="#7f0055">int </font><font color="#000000">MAX_SECONDS = </font><font color="#990000">25</font><font color="#000000">;</font>
<font color="#000000">}</font>
Cheers,
Technofriends Team
Related posts:
- Write a Java Application without a main() method
- Java Roundup
- [Java] Program For Printing Limits of Primitive Data Types
- Java: Lets revisit the past
- [Java] Tips for Becoming a Good Java Developer





[...] How do I declare a constant in Java [...]
[...] read more | digg story [...]