Java Constants


Java constants are the variables that are declared as public/private, final and static and their value never changes from their initial value throughout the program.

If we want to use some value like pi=3.1459 then we do not need to type the value 3.1459 every time, instead we can simply define a constant named as ‘PI’ with value 3.1459.

A constant name should be in completely uppercase letters.


Syntax:

static final dataType ConstantName = ValueOfConstant;

Example:

static final float PI = 3.1459;