Java Reference
In-Depth Information
However, even with 256 characters, the ASCII character set cannot represent
the world's alphabets, especially given the various Asian alphabets and their
many thousands of ideograms. Therefore, the developers of the Java program-
ming language chose the Unicode character set, which uses 16 bits per character,
supporting 65,536 unique characters (and techniques that allow even more char-
acters to be represented using multiple bytes). The characters and symbols from
many languages are included in the Unicode definition. ASCII is a subset of the
Unicode character set, comprising the first 256 characters. Appendix C discusses
the Unicode character set in more detail.
A character set assigns a particular number to each character, so by definition
the characters are in a particular order. This is referred to as lexicographic order.
In the ASCII and Unicode ordering, the digit characters '0' through '9' are
continuous (no other characters intervene) and in order. Similarly, the lowercase
alphabetic characters 'a' through 'z' are continuous and in order, as are the
uppercase alphabetic characters 'A' through 'Z' . These characteristics make it
relatively easy to keep things in alphabetical order.
In Java, the data type char represents a single character. The following are
some examples of character variable declarations in Java:
char topGrade = 'A';
char symbol1, symbol2, symbol3;
char terminator = ';', separator = ' ';
Booleans
A boolean value, defined in Java using the reserved word boolean , has only
two valid values: true and false . A boolean variable is usually used to indicate
whether a particular condition is true, but it can also be used to represent any
situation that has two states, such as a light bulb being on or off.
A boolean value cannot be converted to any other data type, nor can any other
data type be converted to a boolean value. The words true and false are reserved
in Java as boolean literals and cannot be used outside of this context.
The following are some examples of boolean variable declarations in Java:
boolean flag = true ;
boolean tooHigh, tooSmall, tooRough;
boolean done = false ;
SELF-REVIEW QUESTIONS (see answers in Appendix N)
SR 2.14 What is primitive data? How are primitive data types different from
objects?
 
Search WWH ::




Custom Search