The so-called constant, which we can understand as a special variable , whose value is set, is not allowed to change during program operation. Using Constants in your program can improve the maintainability of your code .
The constant value of Java is represented by a string, and the extents are divided into different data types:
1, integral type constant, such as 123
2, the real type constant, such as 3.14
3, character constants, such as ' a '
4, logical constants, such as true, False
5. String constants, such as "HelloWorld"
Note: To differentiate between character constants and string constants, character constants are quoted in single quotes and string constants in double quotes.
Note: The General keyword final indicates that constants with this keyword are not allowed to be changed .
Constant notation for special characters:
Backslash (backslash): \ \
BACKSPACE (Backspace): \b
Return (carriage return): \ r
Paper feed character (Form feed): \f
tab (Form feed): \ t
NewLine (New line): \ n
Single quote: \ '
Octal number (\0~\377): \ddd
Unicode characters: \uhhhh
Constants in Java