Friday, December 30, 2016

2. Literals in java


2. Literals
-------------------------------------------------
Literals is a constant assignment to the variables.

EX:
int a = 10;
where,
int --------> dataType
a ----------> variable[identifier]
= ----------> operator
10 ---------> constant[Literal]
; ----------> special symbol/Terminator

To prepare java application, java has provided the following literal groups:

1. Integer Literal/ Integral Literals:
byte, shot, int, long -------> 10,20,30,....
char ------> 'A', '/n', '/t',.........

2. Floating point Literals:
float ------> 20.30f, 321.023f,.........
double ------> 321.12, 3642.2312,.....

3. String Literal:
String -----> "abc", "xyz",.....

4. Boolean Literal:
Boolean ------> true, false

Note: To improve readability in the literals, java7 has provided a flexibility like to include '_' symbols in middle of the number.
EX:
float f = 1_23_63_234.231f;
System.out.prinln(f);

if we compile the above code then compiler will remove '_' symbol from number, compiler will reformat that as original number, compiler will process
that number as original number only.

No comments:

Post a Comment