Constant is a quantity that will not be modified when the program is running.
Use the final keyword in Java to modify constants, and the declaration method is similar to variables:
finaldouble PI =3.1415927;
Although constant names can also be in lowercase, for ease of identification, capital letters are usually used to represent constants.
Literals can be assigned to variables of any built-in type. For example:
byte a =68; char a ='A'
Byte, int, long, and short can all be represented in decimal, hexadecimal and octal.
When using constants, the prefix 0 represents octal, and the prefix 0x represents hexadecimal. For example:
intdecimal=100; int octal =0144; int hexa =0x64;
Like other languages, Java's string constants are also character sequences contained between two quotation marks. The following are examples of string literals:
"Hello World" "twonlines" ""This is in quotes""
Both string constants and character constants can contain any Unicode characters. For example:
char a ='u0001'; String a ="u0001";
Java language supports some special escape character sequences.
Symbol through Enter(0x0d)
f Backspace(0x08)
s Space (0x20)
t Tab character
" Double quotes
' Single quote
\ Backslash Hexadecimal Unicode characters (xxxx)