Java Reference
In-Depth Information
We illustrate the output and input of binary data by first running BinOutput-
FileApp to produce the data file numerical.dat .Wethen run BinInput-
FileApp ,which reads the file numerical.dat and produces the following
output on the console. Your output will vary since BinOutputFileApp uses
Random to generate random values.
Default: numerical.dat
0. Data = 2.633e+00
1. Data = 7.455e+00
2. Data = 2.447e+00
3. Data = 7.046e+00
4. Data = 2.652e+00
5. Data = 5.120e+00
6. Data = 1.754e+00
7. Data = 7.489e+00
8. Data = 7.386e-01
9. Data = 6.036e+00
10. Data = 7.002e-01
11. Data = 9.625e+00
12. Data = 5.966e+00
13. Data = 8.535e+00
14. Data = 2.744e+00
End of File
9.7 Character encoding
Fortext I/O, each character is specified by an encoded value. The particular type of
encoding, the number of bits and bytes required for the encoding, transformations
between encodings, and other issues thus become important, especially for a
language like Java that is aimed towards worldwide use. So we give a brief
overview of character encodings here.
The 7-bit ASCII code set is the most famous, but there are many extended
8-bit sets in which the first 128 codes are ASCII and the extra 128 codes provide
symbols and characters needed for other languages besides English. For example,
the ISO-Latin-1 set (ISO Standard 8859-1) provides characters for most West
European languages and for a few other languages such as Indonesian.
Java itself is based on the 2-byte Unicode representation of characters. The
16 bits provide for a character set of 65 535 entries and so allows for broad
international use.
The first 256 entries in 2-byte Unicode are identical to the ISO-Latin-1 set. That
makes the 2-byte Unicode inefficient for programs in English since the second
byte is seldom needed. Therefore, a scheme called UTF-8 is used to encode text
characters (e.g. string literals) for the Java class files. The UTF code varies from
 
Search WWH ::




Custom Search