Literals:
(Java is case sensitive language except some cases:
l or L (explicit conversion for long)
b or B (for binary form representaion preceded by 0 ex:0B or 0b)
f or F (for denoting explicitly float )
A-F or a-f (range in Hexadecimal Notation)
x or X (for denoting Hexa form preceded by 0 : ex 0X or 0x)
)
A) Integer Literals:
i) Decimal Representation:10 ,20 ,40
ii) Hexadecimal Literals:0x123A , 0x 343F
iii) Binary Representation: 0b101110
iv) Octal Representation: 0117, 01121
v) (underscore Representation): 1_2__3 ,12_3,1_2_3_4
_ is just a separator which is removed by the compiler.
NOTE:
1.underscore should come only between the numbers.
2. We can have more than one underscore also in between the numbers.
3. Compiler skips all the underscore and represents the integer literals in the actual form.
It means _ representation is provided for the programmers to represent large number easily.
INTEGER Literals are having size 4 byte.
All the integral literals are by default int type.
All the Floating point Literals are of double type by default.
Floating point Literals are having 8-byte size.
B) Floating Point Literals :
i)By use of Decimal point:--2.5, 5.4,-98.2
ii) By use of Exponent:3.4E01,4.2E-23
iii) BY use of Underscore:- 34.3_2,3_4_2.41
not possible :---> ex. 34_.4
General Knowledge:
Float
|
Double
|
1.Single Point Precision.
|
1.Double point Precision.
|
2. Up to 7 points accurate
|
2. Up to 15 points Accurate.
|
3.-3.4e+38 to 3.4e38
|
3. -1.79e308 to 1.79e308
|
Some wrong floating Representation:
float f=012.1;
float f=0x12.3f;
float f=0x12.3;
some Correct Floating representation:
float f=012.1f;
float f=012;
float f=0x12;
RULE:
1. byte->short->int->long->float->double.
2. char->int
C) Character Literals: .
1) Character in single quote:
ex. char c=’d’;
2. By intergral Literals:
char c=10;
3.By unicode representation :
ex char c=\u(XXXX)
where XXXX is hexadecimal Unicode representation.
4.Using Escape Sequence :
in JAVA there is 8 escape sequence :
\n new line
\t tab
\b backspace
\f form feed
\r carriage return
\’ (‘)
\” (“)
\\ (\)
D) String Literals:
i) Represented using double quotes.
Ex “hello”,”test”
_________________________
Comments
Post a Comment
share your thoughts ....