Deck 15: Files,streams and Object Serialization

Full screen (f)
exit full mode
Question
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
Use Space or
up arrow
down arrow
to flip the card.
Question
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.
Question
Which of the following classes is not used for file input?

A)FileInputStream
B)FileReader
C)ObjectInputStream
D)Formatter
Question
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.
Question
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.
Question
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
Question
Path method ________ returns the String name of a file or directory without any location information.

A)getStringName
B)getFileOrDirectoryName
C)getDirectoryName
D)getFileName
Question
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.
Question
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.
Question
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.
Question
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
Question
Adding the services of one stream to another is known as ________.

A)chaining
B)wrapping
C)adding
D)sequencing
Question
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.
Question
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
Question
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
Question
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.
Question
A(n)________ path starts from the directory in which the application began executing.

A)absolute
B)relative
C)parallel
D)comparative
Question
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.
Question
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.
Question
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.
Question
Which JFileChooser method returns the file the user selected?

A)getSelectedFile.
B)getFile.
C)getOpenDialog.
D)showOpenDialog.
Question
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.
Question
The ________ abstract classes are Unicode character-based streams.

A)Reader and Writer
B)BufferedReader and BufferedWriter
C)CharArrayReader and CharArrayWriter
D)UnicodeReader and UnicodeWriter
Question
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.
Question
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.
Question
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
Question
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.
Question
Which JFileChooser method specifies what users can select in the dialog?

A)setFileSelectionMode
B)setSelectionMode
C)showOpenDialog
D)None of the above.
Question
________ 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
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/29
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 15: Files,streams and Object Serialization
1
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
2
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
3
Which of the following classes is not used for file input?

A)FileInputStream
B)FileReader
C)ObjectInputStream
D)Formatter
D
4
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.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
5
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.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
6
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
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
7
Path method ________ returns the String name of a file or directory without any location information.

A)getStringName
B)getFileOrDirectoryName
C)getDirectoryName
D)getFileName
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
8
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.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
9
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.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
10
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.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
11
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
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
12
Adding the services of one stream to another is known as ________.

A)chaining
B)wrapping
C)adding
D)sequencing
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
13
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.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
14
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
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
15
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
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
16
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.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
17
A(n)________ path starts from the directory in which the application began executing.

A)absolute
B)relative
C)parallel
D)comparative
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
18
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.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
19
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.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
20
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.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
21
Which JFileChooser method returns the file the user selected?

A)getSelectedFile.
B)getFile.
C)getOpenDialog.
D)showOpenDialog.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
22
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.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
23
The ________ abstract classes are Unicode character-based streams.

A)Reader and Writer
B)BufferedReader and BufferedWriter
C)CharArrayReader and CharArrayWriter
D)UnicodeReader and UnicodeWriter
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
24
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.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
25
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.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
26
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
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
27
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.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
28
Which JFileChooser method specifies what users can select in the dialog?

A)setFileSelectionMode
B)setSelectionMode
C)showOpenDialog
D)None of the above.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
29
________ 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
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 29 flashcards in this deck.