Programming Languages Chapter 15 Class Scanner Does Not Provide The Ability

subject Type Homework Help
subject Pages 7
subject Words 1779
subject Authors Harvey Deitel, Paul Deitel

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Chapter 15: Files, Streams and Object 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
15.3 Q1: 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.
page-pf2
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
15.3 Q6: Files static method ________ receives a Path and returns a boolean
indicating whether that Path represents a directory on disk.
page-pf3
a. isDiskDirectory
b. isDirectory
c. isFileDirectory
d. isPath
15.3 Q7: 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.
15.4 Sequential-Access Text Files
15.4.1 Creating a Sequential-Access Text File
15.4.1 Q1: 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.
15.4.1 Q2: 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
15.4.2 Reading Data from a Sequential-Access Text File
15.4.2 Q1: 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.
page-pf4
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-Access 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 falserecords in sequential files are usually updated in place.
15.5 Object Serialization
15.5 Q1: 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.
page-pf5
15.5 Q2: 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.
15.5 Q3: Adding the services of one stream to another is known as ________.
a. chaining
b. wrapping
c. adding
d. sequencing
15.5.1 Q1: 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
15.5.1 Q2: 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
15.5.2 Reading and Deserializing Data from a Sequential-
15.5.2 Q1: 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.
page-pf6
15.6 Opening Files with JFileChooser
15.6 Q1: Which JFileChooser method specifies what users can select in the dialog?
a. setFileSelectionMode
b. setSelectionMode
c. showOpenDialog
d. None of the above.
15.6 Q2: Which JFileChooser method returns the file the user selected?
a. getSelectedFile.
b. getFile.
c. getOpenDialog.
d. showOpenDialog.
15.7.1 Interfaces and Classes for Byte-Based Input and Output
15.7.1 Q1: 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.
15.7.1 Q2: ________ is an I/O-performance-enhancement techniqueit 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
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
page-pf7
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 “logicalchunks 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 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.

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.