Types of Literals
Basically, a literal is the source code representation of a fixed value. In order to be able to choose the right answer for some exam questions, you must be able to infer the data type of literals that appear in the sample code of those questions:Literal type | Description | Data type of the literal |
---|---|---|
Integer |
|
|
Floating-point |
|
|
Character |
|
|
String |
|
|
Class |
|
|
Undescores in Numeric Literals
From Java version 7 on, it’s possible to use underscores in numeric literals to improve legibility. They can appear anywhere between the digits of the literal:
1 2 3 4 5 6 7 |
float pi = 3.14_15_927f; byte nybbles = 0b0010_0101; long socialSecurityNumber = 999_99_9999L; |