![]() |
| 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
public static void main(String[] args) 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
public static void main(String[] args) 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
public static void main(String[] args) 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
public static void main(String[] args) System.out.println("Maximum Students Value: " + STUDENTS); } } ============OUTPUT============ Maximum Students Value: 100 |

0 Comments