Java How to Program, 11/e Multiple Choice Test Bank 1 of 7
Chapter 15: Files, Input/Output Streams, NIO and XML
Serialization
15.1 Introduction
15.1 Q1: Which of the following statements is false?
a. Storage of data variables and arrays is temporary.
b. Data is lost when a local variable “goes out of scope.”
c. Files are used for long-term retention of large amounts of data.
d. Data maintained in files is often called transient data.
15.2 Files and Streams
15.2 Q1: Which of the following classes is not used for file input?
a. FileInputStream
b. FileReader
c. ObjectInputStream
d. Formatter
15.2 Q2: How do methods setIn, setOut and setErr affect the standard input, output
and error streams?
a. They output data to the standard input, output and error streams.
b. They provide the only way to access the standard input, output and error streams.
c. They redirect the standard input, output and error streams.
d. They empty the standard input, output and error streams.
15.2 Q3: Streams that input bytes from and output bytes to files are known as ________.
a. bit-based streams
b. byte-based streams
c. character-based streams
d. Unicode-based streams
15.3 Using NIO Classes and Interfaces to Get File and
Directory Information
15.3 Q1: Which of the following statements is false?
a. A Path represents the location of a file or directory.
Java How to Program, 11/e Multiple Choice Test Bank 2 of 7
b. Path objects open files and provide file-processing capabilities.
c. Class Paths is used to get a Path object representing a file or directory location.
d. The static method get of class Paths converts a String representing a file’s or
directory’s location into a Path object.
15.3 Q2: Class ________ provides static methods for common file and directory
manipulations, including methods for copying files; creating and deleting files and
directories; getting information about files and directories; reading the contents of files;
getting objects that allow you to manipulate the contents of files and directories; and
more.
a. File
b. FileAndDirectory
c. Files
d. FilesAndDirectories
15.3 Q3: Which of the following statements is false?
a. A DirectoryStream enables a program to iterate through the contents of a directory.
b. Character-based input and output can be performed with classes Scanner and
Formatter.
c. A relative path contains all the directories, starting with the root directory, that lead to
a specific file or directory.
d. Every file or directory on a disk drive has the same root directory in its path.
15.3 Q4: A(n) ________ path starts from the directory in which the application began
executing.
a. absolute
b. relative
c. parallel
d. comparative
15.3 Q5: Path method ________ returns the String name of a file or directory without
any location information.
a. getStringName
b. getFileOrDirectoryName
c. getDirectoryName
d. getFileName
Java How to Program, 11/e Multiple Choice Test Bank 4 of 7
b. Opens a binary file for output.
c. Opens a text file for input.
d. Opens a text file for output.
15.4.3 Case Study: A Credit-Inquiry Program
15.4.3 Q1: Which of the following statements is true?
a. Class Scanner provides the ability to reposition to the beginning of a file with method
seek.
b. Class Scanner provides the ability to reposition to the beginning of a file with method
reposition.
c. Class Scanner does not provide the ability to reposition to the beginning of the file.
d. If it is necessary to read a sequential file again, the program can simply keep reading—
when the end of the file is reached, the Scanner is automatically set to point back to the
beginning of the file.
15.4.4 Updating Sequential Files
15.4.4 Q1: Records in a sequential file are not usually updated in place. Instead
________.
a. the updated data is placed in a “surrogate” file
b. the entire file is usually rewritten
c. the file is truncated
d. The above statement is false—records in sequential files are usually updated in place.
15.5 XML Serialization
15.5 Q1: Which of the following is false?
a. JAXB (Java Architecture for XML Binding) enables you to perform XML
serialization.
b. Marshaling is the process of deserializing an object.
c. A serialized object is represented by XML that includes the object’s data.
d. XML (eXtensible Markup Language) is a widely used language for describing data.
15.5 Q2: A serialized object is ________.
a. an object represented by XML that includes the object’s data.
b. an object in memory that has been recreated from data in a file
c. a standard output stream object used to convert objects in code to data in a file
Java How to Program, 11/e Multiple Choice Test Bank 5 of 7
d. None of the above.
15.5.1 Creating a Sequential File Using XML Serialization
15.5.1 Q1: Which of the following is false?
a. JAXB works with POJOs (plain old Java objects)—no special superclasses or
interfaces are required for XML-serialization support.
b. JAXB serializes only an object’s public instance variables and public read–write
properties.
c. A class must provide a public default or no-argument constructor to recreate the
objects when they’re read from the file.
d. JAXB requires you to implement special superclasses and interfaces for XML-
serialization support.
15.5.1 Q2: The annotation ________ indicates that a private instance variable should
be serialized.
a. @XMLElement
b. @Element
c. @Marshal
d. @Serialize
15.5.1 Q3: JAXB’s static method ________ serialize objects as XML.
a. toXML
b. serialize
c. marshal
d. None of the above
15.5.2 Reading and Deserializing Data from a Sequential File
15.5.2 Q1: JAXB’s static method ________ deserializes objects from XML.
a. fromXML
b. deserialize
c. unmarshal
d. None of the above
15.6 FileChooser and DirectoryChooser Dialogs
Java How to Program, 11/e Multiple Choice Test Bank 7 of 7
b. Accumulating
c. Amassing
d. Buffering
15.7.1 Q3: Which of the following statements is false?
a. With a BufferedOutputStream each output operation is directed to a buffer large
enough to hold the data of many output operations. Transfer to the output device is
performed in one large physical output operation when the buffer fills.
b. With a BufferedOutputStream, a partially filled buffer can be forced out to the device
at any time by invoking the stream object’s force method.
c. With a BufferedInputStream, many “logical” chunks of data from a file are read as
one large physical input operation into a memory buffer.
d. With a BufferedInputStream, as a program requests data, it’s taken from the buffer.
When the buffer is empty, the next actual physical input operation is performed.
15.7.2 Interfaces and Classes for Character-Based Input and
Output
15.7.2 Q1: The ________ abstract classes are Unicode character-based streams.
a. Reader and Writer
b. BufferedReader and BufferedWriter
c. CharArrayReader and CharArrayWriter
d. UnicodeReader and UnicodeWriter
15.7.2 Q2: Which of the following statements is false?
a. A LineNumberReader is a buffered character stream that tracks the number of lines
read.
b. Classes FileReader and FileWriter perform character-based file I/O.
c. Class PipedReader and class PipedWriter implement piped-character streams for
transferring data between threads.
d. Class StringReader and StringWriter read characters from and write characters to
Streams, respectively.