1.7 v Enhancements with respect to literals
1.7 v Enhancements with respect to literals
1) Binary Literals :- For integral data types untill 1.6 v we can specify literal in the following ways.
*Decimal
*Octal
*Hexa Decimal
But from 1.7 v onwards we can specify literal value even in binary form also. Allowed digits are 0 & 1
Literal value should be prefixed with 0b or 0B.
ex: int x = 0b111; or int x = 0B1111;
2) Usage of underscore symbol in numeric letter. From 1.7 v onwards we can use underscore symbols between digits of numeric literal.
ex: double d = 1_23_456.7_8_9;
The main advantage of this approach is to improve the readability of code.
At the time of compilation these underscoe symbols will be removed automatically.
3) We can use more than 1 underscore symbols also between the digits.
ex: double d = 1___3_4_56.78_9; valid
4) We can use underscore symbols only between the digits. If we are using anywhere else, we will get compile time error.
ex: double d = _1_2_3.4_5; //CE
double d = 1_2_4_5.6_7_; //CE
double d = 1_2_3_.6_7; //CE
byte (1) --> short(2) --> int(4) --> long(8) --> float(4) --> double(8)
^
|
char(2)
* 8 byte long value we can assign to 4 byte float variable because both are following different memory representation completely.
float f = 10l;
o/p = 10.0
Comments
Post a Comment