Java Reference
In-Depth Information
Answers to Review Questions
1.
A stream treats data as bytes, while a reader and writer treats data as characters.
2.
java.io.InputStream is the abstract parent class of all the input stream classes.
3.
They all are, except a writeUTF(String), which is the kind of method you will find in the
high-level streams.
4.
a and e. The other three are high-level streams that only attach to existing streams.
5.
False. PipedInputStream and FileInputStream are both low-level streams, and two low-
level streams cannot be chained together.
6.
True. BufferedReader is a high-level reader and PipedReader is a low-level reader.
7.
True. They are both high-level streams, and any two high-level streams can be chained
together.
8.
You would likely use DataInputStream and DataOutputStream because they contain
methods for reading and writing primitive data types and Strings.
9.
You would likely use the PipedInputStream and PipedOutputStream classes for the two
threads, and the DataInputStream and DataOutputStream classes for filtering the I/O.
10.
I would suggest the FileReader and FileWriter because they are used specifically for
that purpose. In addition, I would recommend the BufferedReader and BufferedWriter
classes to improve performance.
11.
You would likely use the ObjectInputStream and ObjectOutputStream classes, which
perform serialization and deserialization of Java objects.
12.
The read() method returns a single byte, so the answer is b.
13.
True.
14.
False. Marking a field as transient avoids the NotSerializableException.
15.
True. That is the purpose of the transient keyword.
16.
Serializable is a tagging interface and contains no methods.
17.
An IOException if an I/O problem arises, and a ClassNotFoundException if the deserial-
ized object contains a class that the JVM cannot find.
18.
True.
19.
False. Serialized objects are JVM, and are platform independent.
20.
The WARNING level is just below SEVERE (the highest level) in terms of severity, so the
answer is d.
21.
SimpleFormatter, which formats the messages into text, and XMLFormatter, which for-
mats the messages into XML documents.
22.
System.err, the standard error output, which is typically the console.
Search WWH ::




Custom Search