Constant variables in Java

Constant variables in Java

In order to define a constant variable in java, we'll use the final and static keywords.

public class Main {
    final static int CONSTANT_VARIABLE_NAME = 5;
    public static void main(String[] args) {
        //compilation error
        CONSTANT_VARIABLE_NAME = 5;

        //Define constant in block of code
        final int CONSTANT_VARIABLE_BLOCK_NAME = 5;
    }
}