Literal : Any constant value which can be assigned to the variable is called as literal/constant.
- Decimal literals (Base 10) : In this form the allowed digits are 0-9.
int x = 101;
- Octal literals (Base 8) : In this form the allowed digits are 0-7.
// The octal number should be prefix with 0. int x = 0146;
- Hexa-decimal literals (Base 16) : In this form the allowed digits are 0-9 and characters are a-f. We can use both uppercase and lowercase characters. As we know that java is a case-sensitive programming language but here java is not case-sensitive.
// The hexa-decimal number should be prefix // with 0X or 0x. int x = 0X123Face;
- Binary literals : From 1.7 onward we can specify literals value even in binary form also, allowed digits are 0 and 1. Literals value should be prefixed with 0b or 0B.
int x = 0b1111;