Java Constants Naming Convention

Java Constants Naming Convention
Java Constants Naming Convention

Constants in Java: A Java constant is a element of program value can not be changed at the time of execution of program is called constant. Constant is also called literals. It may be integer, floating and character data type.

Integer Constant in Java

Integer Constant: A Integer constant must have at least one digit. It is not have any decimal point numbers. It may be positive or negative and no comma or blank space are allowed in integer constant.

Integer Constant in Java Program

class Jiocoding{
public static void main(String[] args)
{
int year=2026;
System.out.println("Integer Constant Value:"+year);
}
}
============OUTPUT============
Integer Constant Value:2026

Floating Point Constant in Java

Float Constant: A float constant must have at least one digit. It is also have a one decimal point number. It may be positive or negative and no comma or blank space are allowed in floating point constant.

Example Float Constant in Java Program

class Jiocoding{
public static void main(String[] args)
{
float pi=3.147;
System.out.println("Float Constant Value:"+pi);
}
}
============OUTPUT============
Float Constant Value:3.147

Character Constant in Java

Character Constant: A character constant is a single alphabet, digit or special symbol are including in character constant. The length of character constant is 1 character. enclosed within single quotes.

Example of Character Constant in Java

class Jiocoding{
public static void main(String[] args)
{
char cj='J';
System.out.println("Character Constant Value:"+jc);
}
}
============OUTPUT============
Character Constant Value: J

Final and Constant in Java

Final Constant: A final keyword can not use a variable name value to change use the final keyword. A variable declared with final constant means not changeable.

You can declared variables as final keyword values should never change. the number of second in an minutes, year.

Example of Character Constant in Java

class Jiocoding{
public static void main(String[] args)
{
static final int STUDENTS = 100;
System.out.println("Maximum Students Value: " + STUDENTS);
}
}
============OUTPUT============
Maximum Students Value: 100

Conclusion of Constant in Java

Conclusion: A Java constant can be used where value are not changeable. It is a fixed value you can directly value change but run time value not change. You can learn java constant next article if you can face problems constant than you can contact me by email or comments.  

Post a Comment

0 Comments