Deck 17: Files,streams and Object Serialization

Full screen (f)
exit full mode
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.
Use Space or
up arrow
down arrow
to flip the card.
Question
What does the following statement do? Scanner scanner = new Scanner( new File( "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 is arranged in increasing size order?

A)field,bit,file,record.
B)byte,file,database,record.
C)byte,field,file,record.
D)bit,field,record,file.
Question
Which of the following statements is false?

A)The smallest data item a computer can assume is the value 0 or the value 1.
B)The term "bit" is short for "byte digit."
C)Java uses the Unicode character set.
D)A record is typically composed of several fields.
Question
Which of the following statements is not equivalent to File name = new File( "c:\\books\\2009\\files.txt" );
Assume we are currently in the directory c:\books.

A)File name = new File( "c:\\books\\2009","files.txt" );
B)File name = new File( "files.txt" );
C)File name = new File( "2009","files.txt" );
D)All of the above are equivalent to the statement in the question.
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)IOOutput.
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
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
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 is not an application of a File object?

A)Open or edit a file.
B)Determine if a file exists.
C)Determine whether a file is readable.
D)Determine whether a file is writable.
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
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
Adding the services of one stream to another is known as

A)chaining.
B)wrapping.
C)adding.
D)sequencing.
Question
Relative paths normally start from which directory?

A)The directory in which the application began executing.
B)The root directory.
C)The directory in which the Java interpreter is installed.
D)None of the above.
Question
What happens when an end-of-file marker is reached (and the program is using an ObjectInputStream to read data from a file)?

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 classes is not used for file input?

A)FileInputStream
B)FileReader
C)ObjectInputStream
D)Formatter
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 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
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
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
Which method call enables users to specify that a user can select files and directories from a JFileChooser?

A)setFileSelectionMode( FILES_OR_DIRECTORIES );
B)showOpenDialog( FILES_AND_DIRECTORIES );
C)showOpenDialog( FILES_OR_DIRECTORIES );
D)None of the above.
Question
Which JFileChooser method returns the file the user selected.

A)getSelectedFile.
B)getFile.
C)getOpenDialog.
D)showOpenDialog.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/22
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 17: Files,streams and Object Serialization
1
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
2
What does the following statement do? Scanner scanner = new Scanner( new File( "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
3
Which of the following is arranged in increasing size order?

A)field,bit,file,record.
B)byte,file,database,record.
C)byte,field,file,record.
D)bit,field,record,file.
D
4
Which of the following statements is false?

A)The smallest data item a computer can assume is the value 0 or the value 1.
B)The term "bit" is short for "byte digit."
C)Java uses the Unicode character set.
D)A record is typically composed of several fields.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following statements is not equivalent to File name = new File( "c:\\books\\2009\\files.txt" );
Assume we are currently in the directory c:\books.

A)File name = new File( "c:\\books\\2009","files.txt" );
B)File name = new File( "files.txt" );
C)File name = new File( "2009","files.txt" );
D)All of the above are equivalent to the statement in the question.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
6
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)IOOutput.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
7
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 22 flashcards in this deck.
Unlock Deck
k this deck
8
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 22 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 22 flashcards in this deck.
Unlock Deck
k this deck
10
Which of the following is not an application of a File object?

A)Open or edit a file.
B)Determine if a file exists.
C)Determine whether a file is readable.
D)Determine whether a file is writable.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
11
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 22 flashcards in this deck.
Unlock Deck
k this deck
12
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 22 flashcards in this deck.
Unlock Deck
k this deck
13
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 22 flashcards in this deck.
Unlock Deck
k this deck
14
Relative paths normally start from which directory?

A)The directory in which the application began executing.
B)The root directory.
C)The directory in which the Java interpreter is installed.
D)None of the above.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
15
What happens when an end-of-file marker is reached (and the program is using an ObjectInputStream to read data from a file)?

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 22 flashcards in this deck.
Unlock Deck
k this deck
16
Which of the following classes is not used for file input?

A)FileInputStream
B)FileReader
C)ObjectInputStream
D)Formatter
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
17
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.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
18
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 22 flashcards in this deck.
Unlock Deck
k this deck
19
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 22 flashcards in this deck.
Unlock Deck
k this deck
20
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 22 flashcards in this deck.
Unlock Deck
k this deck
21
Which method call enables users to specify that a user can select files and directories from a JFileChooser?

A)setFileSelectionMode( FILES_OR_DIRECTORIES );
B)showOpenDialog( FILES_AND_DIRECTORIES );
C)showOpenDialog( FILES_OR_DIRECTORIES );
D)None of the above.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
22
Which JFileChooser method returns the file the user selected.

A)getSelectedFile.
B)getFile.
C)getOpenDialog.
D)showOpenDialog.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 22 flashcards in this deck.