Java Reference
In-Depth Information
The hexadecimal form consists of 0x (or 0X), a string of hexadecimal di-
gits with an optional hexadecimal point, followed by a mandatory binary
exponentthe letter
p
or
P
, followed by an optionally signed integer. The
binary exponent represents scaling by two raised to a power. All these
literals also denote the same floating-point number (decimal 18.0):
0x12p0 0x1.2p4 0x.12P+8 0x120p-4
Floating-point constants are of type
double
unless they are specified with
a trailing
f
or
F
, which makes them
float
constants, such as
18.0f
. A
trailing
d
or
D
specifies a
double
constant. There are two zeros: posit-
ive (
0.0
) and negative (
-0.0
). Positive and negative zero are considered
equal when you use
==
but produce different results when used in some
calculations. For example, if dividing by zero, the expression
1d/0d
is +
, whereas
1d/-0d
is
-
. There are no literals to represent either infin-
ity or NaN, only the symbolic constants defined in the
Float
and
Double
A
double
constant cannot be assigned directly to a
float
variable, even if
the value of the
double
is within the valid
float
range. The only constants
you may directly assign to
float
variables and fields are
float
constants.
7.2.6. String Literals
String literals appear with double quotes:
"along"
. Any character can be
included in string literals, with the exception of newline and
"
(double
quote). Newlines are not allowed in the middle of strings. If you want to
embed a newline character in the string, use the escape sequence
\n
. To
embed a double quote use the escape sequence
\"
. A string literal refer-