Page 493 - Introduction to Programming with Java: A Problem Solving Approach
P. 493

                Output:
Up Down
15
24
33
42
51
As with many of the techniques presented in this chapter, using multiple initialization and update compo- nents in a for loop is a bit of an art. It leads to more compact code, which can be a good thing or a bad thing. If the compact code is more understandable, use it. If the compact code is more cryptic, don’t use it.
11.13 GUI Track: Unicode (Optional)
Earlier, you learned that characters get their underlying numeric values from the ASCII character set. That’s true for the 128 characters shown in Figure 11.4, but be aware that there are way more than 128 characters in the world. The ASCII character set contains the characters in the Latin alphabet—A through Z—but it does not contain the characters in other alphabets. For example, it does not contain the characters in the Greek, Cyrillic, and Hebrew alphabets. The designers of the Java language wanted Java to be general purpose, so they wanted to be able to produce text output for many different languages using many different alphabets. To handle the additional characters, the Java designers had to use a bigger character set than the ASCII character set. Thus, they adopted the Unicode standard. The Unicode standard defines underlying numeric values for a huge set of 65,536 characters.
11.13 GUI Track: Unicode (Optional) 459
  Apago PDF Enhancer
Why are there 65,536 characters in the Unicode standard? Because the people who designed the Uni-
code standard (the Unicode Consortium) decided that 16 bits would be sufficient to represent all the char-
4
acters needed in a computer program. And 16 bits can represent 65,536 characters. Here are the binary
representations for the first four characters and the last character:
0000 0000 0000 0000 0000 0000 0000 0001 0000 0000 0000 0010 0000 0000 0000 0011 .. .
1111 1111 1111 1111
Notice that each row is a different permutation of 0’s and 1’s. If you wrote all such permutations, you’d see 65,536 rows. Thus, with 16 bits, you can represent 65,536 characters. The formula for determining the num- ber of permutations (and consequently the number of rows and the number of characters) is 2 raised to the power of the number of bits. In other words, 216 􏰂 65,536.
You can apply that same reasoning in determining why there are 128 characters in the ASCII character set. Way back in 1963 (when dinosaurs roamed the earth), the people who designed the ASCII character set
4 We’re focusing on the original Unicode standard, which is a subset of the current Unicode standard. The original Unicode standard is good enough for almost all Java programming. The original Unicode standard uses 16 bits for all characters. The current Unicode standard uses additional bits for additional characters that can’t fit in the original Unicode set of 65,536 values. For additional details, see http://www.unicode.org/.
 












































































   491   492   493   494   495