Java Reference
In-Depth Information
All floating-point literals are considered to be of the double variable type instead of
float . To specify a literal of float , add the letter F (upper- or lowercase) to the literal,
as in the following example:
float piValue = 3.1415927F;
You can use exponents in floating-point literals by using the letter e or E followed by the
exponent, which can be a negative number. The following statements use exponential
notation:
double x = 12e22;
double y = 19E-95;
Boolean Literals
The Boolean literals true and false are the only two values you can use when assigning
a value to a boolean variable type or using a Boolean in a statement.
The following statement sets a boolean variable:
boolean chosen = true;
If you have programmed in other languages, you might expect that a value of 1 is equiva-
lent to true and 0 is equivalent to false. This isn't the case in Java; you must use the val-
ues true or false to represent Boolean values.
Note that the literal true does not have quotation marks around it. If it did, the Java
compiler would assume that it was a string.
Character Literals
Character literals are expressed by a single character surrounded by single quotation
marks, such as 'a', '#', and '3'. You might be familiar with the ASCII character set,
which includes 128 characters, including letters, numerals, punctuation, and other char-
acters useful in computing. Java supports thousands of additional characters through the
16-bit Unicode standard.
Some character literals represent characters that are not readily printable or accessible
through a keyboard. Table 2.2 lists the special codes that can represent these special
characters as well as characters from the Unicode character set. In Table 2.2, the letter d
in the octal, hex, and Unicode escape codes represents a number or a hexadecimal digit
(a-f or A-F).
Search WWH ::




Custom Search