Literals in JAVA
LITERAL
NON NUMERIC LITERAL
NUMERIC LITERAL
character Literal boolean Literal
Integer Literal Real Literal
String Literal
int Literal null Literal
float Literal double Literal
Decimal Integer Literal
long Literal
Octal Integer Literal
short Literal
Hexadecimal Integer Literal
byte Literal
Literal Type Description
byte Literal Smallest value – 128 and Largest value 127
short Literal Smallest value – 32768 and Largest value 32767
Decimal integer Any positive or negative value contains unique digits 0 to 9.
Literal Example: - 45 , 1000 , 637
Octal integer Any positive or negative value contains unique digits 0 to 7 and
Literal the literal starts with leading zero. Example: 010 , 077
Any positive or negative value contains unique digits 0 to 9 then
Hexadecimal
A to F and the literal starts with leading zero with X or x.
integer Literal Example: 0X10 , 0x77, 0xAB , 0XC7
long Literal This type of literal ends with either L or l. Example: 32L , 425l
This type of literal ends with either F or f. Example: 32F , 32.5f ,
float Literal
35.75F
This type of literal ends with either D or d or not. Example: 3.2 ,
double Literal
4.25d , 2D
boolean Literal It is only two types true and false
It is enclosed within single quote and ASCII comparison is
character Literal
possible. Example: ‘A’ , ‘5’ , ‘+’ , ‘\u0000’
It is enclosed within double quote and ASCII comparison is not
String Literal
possible. Example: “2D” , “95” , “A+” , “Face”
When we declare a literal with \0 then it is termed as null literal
null Literal in Java. The null is a reserve word in Java not a keyword. It is
basically used the default value of an object.