What is Java Const in Programming?

Published: 30th September 2010
Views: N/A

Different object-oriented programming languages have their own distinct keywords. For example, C++ and Java programming has their own sets of variable and identifiers. While in Java programming, there are many keywords that could be used by developers to write out functions and methods for computer programs and applications. All of it has unique usages and importance. Among the examples of it are abstract, class and char.

However among all of it, there is one called java const. This could also be stated as constant modifier. In Java programming, it actually has not much been used for it serves no function at all. Java does not directly support constants. But to utilise it, creating a static final variable is a way to produce a result of a constant. The static will enable the variable to load an instance of the class and makes it unchangeable or immutable. An example of how a constant is written:

public class MAX_UNITS {

public static final int MAX_UNITS = 65;


In the example above, ‘public’ refers to any declarations of methods or field which could be accessed by the members of any class. ‘class’ is defining instance. The modifier ‘static’ and ‘final’ is what makes up the java const function. ‘int’ is a keyword to declare a field of 32 bit. ‘static’ ensures that whatever fields in the class remains the same in all instances. The modifier ‘final’ is what makes the value in the field unchanged as the program runs. When it is being placed there, it means to tell the compiler that the value or integer cannot be change during execution or the programming codes, thus giving the function of a constant.

Using a constant or ‘final’ modifier helps the programming codes to be cleaner and easy to follow. It also makes sure there is consistency of programs as it executes.

Chris has written this article and likes to share articles on topics like java const and java data types .

Report this article Ask About This Article

More to Explore