Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
90 views

Literals in Java

Literals in Java can be numeric literals such as integer, real, or boolean literals or non-numeric literals such as character or string literals. Numeric literals include integer literals which can be decimal, octal, or hexadecimal, real literals which can be float or double, and boolean literals which are true or false. Non-numeric literals include character literals enclosed in single quotes and string literals enclosed in double quotes.

Uploaded by

Aryan Dwivedi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Literals in Java

Literals in Java can be numeric literals such as integer, real, or boolean literals or non-numeric literals such as character or string literals. Numeric literals include integer literals which can be decimal, octal, or hexadecimal, real literals which can be float or double, and boolean literals which are true or false. Non-numeric literals include character literals enclosed in single quotes and string literals enclosed in double quotes.

Uploaded by

Aryan Dwivedi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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.

You might also like