constant int java code example
Example 1: constants in Java
//A constant is a variable whose value won't change after it's been defined.
private static final int OUR_CONSTANT = 1;
//We make our constants static and final and give them an appropriate type,
//whether that's a Java primitive, a class, or an enum.
//The name should be all capital letters with the words separated by underscores,
//sometimes known as screaming snake case.
Example 2: how to make a variable unchangeable in java
class scratch{
public static void main(String[] args){
final pi = 3.14;
}
}
Example 3: constant java declaration
final double Pi = 3.1415926536;