Java const Keyword
Example
Java does not use const. Use final to create a variable that cannot change:
public class Main {
public static void main(String[] args) {
final int myNum = 15;
System.out.println(myNum);
}
}
Definition and Usage
The const keyword is reserved in Java, but it is not used. You cannot use it in your code, and you cannot use it as a name for a variable, method or class.
To create a constant (a variable that cannot change), use the final keyword instead, like in the example above. If you try to change myNum later, Java gives an error.
Related Pages
Read more about constants in our Java Constants (final) Tutorial.