constant variable java code example
Example 1: constants in Java
private static final int OUR_CONSTANT = 1;
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;
Example 4: create constant class in java
public final class MyValues {
public static final String VALUE1 = "foo";
public static final String VALUE2 = "bar";
}
Example 5: what are constants and how to create constants in java
Constants are fixed values whose values cannot be changed during
the execution of program. We create constants in java using final keyword.
Ex : final int number = 10;
final String str = ”I love Java”;