Java Reference
In-Depth Information
Figure 2.3
Output of the BooleanDemo program.
In Java, a boolean data type is not an integer value. A boolean can be only
true or false, two special Java literals. In other languages, Boolean values
are integer types, with 0 being false and a nonzero entry being considered
true. Notice in the BooleanDemo program that the boolean y cannot be
assigned to the int x, even if casting is attempted.
Char Data Type
The char data type represents characters in Java. The size of a char is 16 bits,
which allows characters to be represented as integers using the Unicode char-
acter mapping. A char can be treated as an integer value, allowing you to per-
form arithmetic and make comparisons using greater than or less than. Just
keep in mind that char is an unsigned data type.
Single quotes are used to denote a character literal. For example, the literal
'A' in your code would be treated as a char. (If a literal appears in double
quotes, like “A”, it is not a char, it is a String.) Some characters that are not
printable are denoted using the escape sequence \. Table 2.3 provides a list of
some of the more commonly used escape sequence characters.
Table 2.3
Escape Sequence Characters
ESCAPE SEQUENCE
DEFINITION
\t
tab
\b
backspace
\n
newline
\r
carriage return
\'
single quote
\”
double quote
\\
backslash
Search WWH ::




Custom Search