Content in java Programming language :-
Constant:
A constant is a special type of variable whose value cannot change once it has been assigned.
Java does not have built-in support for constant.
A constant can make our program more easy read and understood by others.
What is constant variable?
Constant is a special types of variable whose value cannot change if one it has been assigned.
to define a variable as a constant we just need to add final keyword before variable declaration. Java does not directly support constant to make any variable a constant we must use a static and final modifier before any variable.
Syntax:
Static final datatype identifier_name = constant;
Hence, static and final is a modifiers.
Ex.
final int a = 33;
&
static int b= 40;
the above statement declares the integer variable a has a constant with the value of 30 we cannot change the value of at any point in time in the program later if you try to change value like is " a = 5 " Java will throw error at compile time itself.
Program for understand constant concept
Public Class DemoConstant
{
Public static void main ( String arg [ ] )
{
final int a = 100;
final boolean c = true;
final float b = 99.99f;
final char d = 'S';
System.out.println (" Value of a : = " +a);
System.out.println (" Value of b : = " +b);
System.out.println (" Value of c : = " +c);
System.out.println (" Value of d : = " +d);
}
}