Chapter 15: Files, Streams and Object Serialization
A serialized object is ________. a. an object represented as a sequence of bytes used to store the object's data in a file 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 d. None of the above.
a. An object represented as a sequence of bytes used to store the object's data in a file.
The ________ abstract classes are Unicode character-based streams. a. Reader and Writer b. BufferedReader and BufferedWriter c. CharArrayReader and CharArrayWriter d. UnicodeReader and UnicodeWriter
a. Reader and Writer
Which JFileChooser method returns the file the user selected? a. getSelectedFile. b. getFile. c. getOpenDialog. d. showOpenDialog.
a. getSelectedFile
Which JFileChooser method specifies what users can select in the dialog? a. setFileSelectionMode b. setSelectionMode c. showOpenDialog d. None of the above.
a. setFileSelectionMode
: Which of the following classes enable input and output of entire objects to or from a file? A. SerializedInputStream B. SerializedOutputStream C. ObjectInputStream D. ObjectOutputStream E. Scanner F. Formatter a. A and B. b. C and D. c. C, D, E, F. d. E and F.
b. C and D
Files static method ________ receives a Path and returns a boolean indicating whether that Path represents a directory on disk. a. isDiskDirectory b. isDirectory c. isFileDirectory d. isPath
b. IsDirectory
Which of the following statements is false? a. InputStream and OutputStream are abstract classes for performing byte-based I/O. b. Tubes are synchronized communication channels between threads. c. A filter stream provides additional functionality, such as aggregating data bytes into meaningful primitive-type units. FilterInputStream and FilterOutputStream are typically extended, so some of their filtering capabilities are provided by their concrete subclasses. d. A PrintStream performs text output. System.out and System.err are PrintStreams.
b. Tubes are synchronized communication channels between threads.
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.
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.
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
b. byte-based streams
Which of the following statements is false? a. A Path represents the location of a file or directory. 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.
b. path objects open files and provide file-processing capabilities.
A(n) ________ path starts from the directory in which the application began executing. a. absolute b. relative c. parallel d. comparative
b. relative
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
b. the entire file is usually rewritten
Adding the services of one stream to another is known as ________. a. chaining b. wrapping c. adding d. sequencing
b. wrapping
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.
c. A relative path contains all the directories, starting with the root directory, that lead to a specific file or directory.
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.
c. Class scanner does not provide the ability to reposition to the beginning of the file.
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
c. Files
: What interface must a class implement to indicate that objects of the class can be output and input as a stream of bytes? a. Synchronize b. Deserializable c. Serializable d. ObjectOutput
c. Serializable
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.
c. The redirect the standard input, output, and error streams.
What does the following statement do? Scanner scanner = new Scanner(Paths.get("test.txt")); a. Opens a binary file for input. b. Opens a binary file for output. c. Opens a text file for input. d. Opens a text file for output.
c. opens a text file for input.
Instance variables that are not to be output with a Serializable object are declared using which keyword? a. private b. ignoreme c. transient d. persistent
c. transient
Which of the following statements is false? a. Path method isAbsolute returns a boolean indicating whether a Path represents an absolute path to a file or directory. b. Files static method getLastModifiedTime receives a Path and returns a FileTime (package java.nio.file.attribute) indicating when the file was last modified. c. Files static method size receives a Path and returns a long representing the number of bytes in the file or directory. For directories, the value returned is platform specific. d. All of the above are true.
d. All of the above are true
When using an ObjectInputStream to read data from a file, what happens when an end-of-file marker is reached? a. Nothing occurs. b. An end-of-file character is read by the program. c. Method readObject returns the value 0. d. An EOFException is thrown.
d. An EOFException is thrown
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.
d. Class StringReader and StringWriter read characters from and write characters to Streams respectively.
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.
d. Data maintained in files is often called transient data
Which of the following classes is not used for file input? a. FileInputStream b. FileReader c. ObjectInputStream d. Formatter
d. Formatter
Which statement regarding Java files is false? a. Java imposes no structure on a file. b. Notions like "record" do not exist in Java files. c. The programmer must structure files to meet the requirements of applications. d. Records in a Java sequential file are stored in order by record key.
d. Records in a java file are stored in order by record key.
When all the contents of a file are truncated, this means that ________. a. the data in the file is saved to a backup file b. the file is deleted c. a FileNotFoundException occurs d. all the data in the file is discarded
d. all the data in the file is discarded.
________ is an I/O-performance-enhancement technique—it reduces the number of I/O operations by combining smaller outputs together in memory; the number of physical I/O operations is much smaller than the number of I/O requests issued by the program. a. Aggregating b. Accumulating c. Amassing d. Buffering
d. buffering
Path method ________ returns the String name of a file or directory without any location information. a. getStringName b. getFileOrDirectoryName c. getDirectoryName d. getFileName
d. getFileName