Java Reference
In-Depth Information
type char when enclosed in single quotation marks. All the individual symbols located on
the keyboard that are printable are considered possible values of the char data type.
As stated in Chapter 1, each character has a specific representation in computer memory,
and there are several different coding schemes for characters. Java uses the Unicode
character set, which contains 65536 values numbered 0 to 65535. The position of the
first character is 0, the position of the second character is 1, and so on. Other commonly
used character data sets are the American Standard Code for Information Interchange
(ASCII) and Extended Binary-Coded Decimal Interchange Code (EBCDIC).
The ASCII character set has 128 values. ASCII is a subset of Unicode. That is, the first
128 characters of Unicode are the same as the characters in ASCII. The EBCDIC
character set has 256 values and was created by IBM.
Each of the 65536 values of the Unicode character set represents a different character. For
example, the value 65 represents 'A' , and the value 43 represents '+' . Thus, each
character has a specific non-negative integer value in the Unicode character set, which is
called a collating sequence, of the character. It follows that the collating sequence of
'A' is 65. The collating sequence is used when you compare characters. For example, the
value representing 'B' is 66 ,so 'A' is smaller than 'B' . Similarly, '+' is smaller than
'A' because 43 is smaller than 65 .
The 14th character in the Unicode (and ASCII) character set is called the newline character
and is represented as '\n' . (Note that the position of the newline character in the Unicode
and ASCII character sets is 13 because the position of the first character is 0.) Even though
the newline character is a combination of two characters, it is treated as one character.
Similarly, the horizontal tab character is represented in Java as '\t' , and the null character
is represented as '\0' (a backslash followed by zero). (Later in this chapter, we elaborate
on these special characters.) Furthermore, the first 32 characters in the Unicode and ASCII
character sets are nonprintable. (See Appendix C for a list of these characters.)
boolean DATA TYPE
The data type boolean has only two values: true and false . Also, true and false are
called the logical (Boolean) values. The primary purpose of this data type is to manipulate
logical (Boolean) expression. An expression that evaluates to true or false is called a
logical (Boolean) expression. Logical (Boolean) expressions are formally defined and
discussed in detail in Chapter 4. In Java, boolean , true , and false are reserved words.
The memory allocated for the boolean data type is 1 bit.
FLOATING-POINT DATA TYPES
To deal with decimal numbers, Java provides the floating-point data type. To facilitate
our discussion of this data type, we will review a concept from a high school or college
algebra course.
You may be familiar with scientific notation. For example:
43872918 = 4.3872918 * 10 7
.0000265 = 2.65 * 10 -5
47.9832 = 4.7983 * 10 1
Search WWH ::




Custom Search