Java Reference
In-Depth Information
Octal character constants can have three or fewer digits and cannot ex-
ceed
\377
(
\u00ff
)for example, the character literal
'\12'
is the same as
'\n'
. Supplemental characters can not be represented in a character lit-
eral.
7.2.4. Integer Literals
Integer constants are strings of octal, decimal, or hexadecimal digits.
The start of a constant declares the number's base: A
0
(zero) starts an
octal number (base 8); a
0x
or
0X
starts a hexadecimal number (base
16); and any other digit starts a decimal number (base 10). All the fol-
lowing numbers have the same value:
29 035 0x1D 0X1d
Integer constants are
long
if they end in
L
or
l
, such as
29L
;
L
is preferred
over
l
because
l
(lowercase
L
) can easily be confused with
1
(the digit
one). Otherwise, integer constants are assumed to be of type
int
. If an
int
literal is directly assigned to a
short
, and its value is within the val-
id range for a
short
, the integer literal is treated as if it were a
short
literal. A similar allowance is made for integer literals assigned to
byte
variables. In all other cases you must explicitly cast when assigning
int
7.2.5. Floating-Point Literals
Floating-point constants are expressed in either decimal or hexadecimal
form. The decimal form consists of a string of decimal digits with an op-
tional decimal point, optionally followed by an exponentthe letter
e
or
E
, followed by an optionally signed integer. At least one digit must be
present. All these literals denote the same floating-point number:
18. 1.8e1 .18E+2 180.0e-1