Java How To Program, 5/e Test Item File 1 of 5

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Java How to Program, 5/e Test Item File 1 of 5

Chapter 17

Section 17.1

17.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.
ANS: d. Data maintained in files is often called transient data.

17.1 Q2: File processing programs are generally implemented in Java as __________.
a.Applets.
b.Multithreaded programs.
c.Applications.
d.Interfaces.
ANS: c. Applications.

Section 17.2

17.2 Q1: Which statement is false?


a.The smallest data item in a computer can assume the value 0 or the value 1.
b.The term "bit" is short for "byte digit."
c.Java Unicode characters are composed of 2 bytes each.
d. A record is typically composed of several fields.
ANS: b. The term "bit" is short for "byte digit."

17.2 Q2: 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.
ANS: d. Bit, field, record, file.

Section 17.3

17.3 Q1: __________ is an I/O performance enhancement technique.


a.Buffering.
b.Piping.
c.Pushback.
d.Transaction processing.
ANS: a. Buffering.

17.3 Q2: __________ are synchronized communication channels between threads.


a.Files.
b.Buffers.
c.Interfaces.
d.Pipes.
ANS: d. Pipes.

17.3 Q3: How do methods setIn, setOut and setErr affect the standard input, output and error streams?
a.They wrap the streams around another stream.
b.They toggle the buffering capability of these streams.
c.They redirect the standard input, output and error streams.
d.They flush these streams’ buffers.
ANS: c. They redirect the standard input, output and error streams.

17.3 Q4: System.out and System.err are objects of what class?


a.PipedOutputStream.
b.FileOutputStream.

© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.
Java How to Program, 5/e Test Item File 2 of 5

c.PrintStream.
d.BufferedOutputStream.
ANS: c. PrintStream.

Section 17.4

17.4 Q1: 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.
ANS: a. Open or edit a file.

17.4 Q2: To insert a \ in a string literal you must use __________.


a.//.
b./.
c.\\.
d.\".
ANS: c. \\.

17.4 Q3: Relative paths 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.
ANS: a. The directory in which the application began executing.

17.4 Q4: Adding the services of one stream to another is known as


a.chaining.
b.wrapping.
c.adding.
d.sequencing.
ANS: b. wrapping.

Section 17.5

17.5 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.
ANS: d. Records in a Java sequential file are stored in order by record key.

17.5 Q2: When displayed, a JFileChooser dialog does not allow the user to interact with any other program
window until the JFileChooser dialog is closed. Dialogs that behave in this fashion are called __________
dialogs.
a.Synchronized.
b.Modal.
c.Median.
d.Choice.
ANS: b. Modal.

17.5 Q3: What interface allows objects to be converted to a series of bytes?


a.Synchronized.
b.Output.
c.Serializable.
d.Permanent.
ANS: c. Serializable.

© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.
Java How to Program, 5/e Test Item File 3 of 5

17.5 Q4: Instance variables that are not to be output with that object are declared using which keyword?
a.private.
b.temporary.
c.transient.
d.ignore.
ANS: c. transient.

Section 17.6

17.6 Q1: RandomAccessFile method __________ repositions the file-position pointer to any position in the file.
a.seek .
b.search.
c.serve.
d.set.
ANS: a. seek.

17.6 Q2: 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.The program crashes.
d.An EOFException is thrown.
ANS: d. An EOFException is thrown.

17.6 Q3: The file-position pointer


a.always points to the beginning of the file.
b.always points to the end of the file.
c.points to the next byte in the file to be read or written to.
d.is a reference to a File object.
ANS: c. points to the next byte in the file to be read or written to.

17.6 Q4: When a file is opened, the file-position pointer


a.is undefined.
b.points to the beginning of the file.
c.points to the end of the file.
d.is positioned where it was when the file was closed.
ANS: b. points to the beginning of the file.

Section 17.7

17.7 Q1: Which statement is false?


a.Updating only a small portion of a sequential-access file is a relatively expensive operation.
b.Updating a large portion of a sequential-access file is a relatively efficient operation.
c.Updating a sequential-access file typically involves copying the file.
d.Updating only a small portion of a sequential-access file is a relatively efficient operation.
ANS: d. Updating only a small portion of a sequential-access file is a relatively efficient operation.

Section 17.8

17.8 Q1: Which statement is true?


a.Sequential-access files are appropriate for "instant-access" applications.
b.Transaction-processing systems are good examples of "instant-access" applications.
c.Data cannot be inserted in a random-access file without destroying other data in the file.
d.Airline reservation systems, point-of-sale systems, and automated teller machines are best
implemented as sequential-access applications.
ANS: b. Transaction-processing systems are good examples of “instant-access” applications.

© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.
Java How to Program, 5/e Test Item File 4 of 5

17.8 Q2: Random-access files are sometimes called


a.direct-access files.
b.sequential-access files.
c.instant-access files.
d.None of the above.
ANS: a. direct-access files.

Section 17.9

17.9 Q1: When a RandomAccessFile stream is associated with a file, data is read or written beginning at the
location in the file specified by the __________.
a.File-location pointer.
b.Read/write pointer.
c.File-position pointer.
d.Transaction pointer.
ANS: c. File-position pointer.

17.9 Q2: Which statement is false?


a.Swing components display null byte characters as rectangles.
b.The file open mode for a RandomAccessFile can be "r" to open the file for reading.
c.The file open mode for a RandomAccessFile can be "w" to open the file for writing.
d.The file open mode for a RandomAccessFile can be "rw" to open the file for reading and writing.
ANS: c. The file open mode for a RandomAccessFile can be “w” to open the file for writing.

17.9 Q3: The null byte is represented by what escape-sequence?


a.'\n'.
b.'\e'.
c.'\s'.
d.'\0'.
ANS: d. '\0'.

Section 17.10

17.10 Q1: What method sets the file-position pointer?


a.seek.
b.place.
c.setPosition.
d.setPos.
ANS: a. seek.

Section 17.11

17.11 Q1: Which statement about sorting with direct access techniques is false?
a.It can be blazingly fast compared to the bubble sort.
b.It uses storage efficiently.
c.It uses large amounts of storage relative to the actual space needed to hold the items being sorted.
d.If often wastes storage.
ANS: b. It uses storage efficiently.

17.11 Q2: Which statement is false? Open a file with the "r" mode …
a.To be able to read from the file.
b.To prevent unintentional modification of the file's contents.
c.To implement the "principle of least privilege."
d.To allow writing only at the end of the file.
ANS: d. To allow writing only at the end of the file.

Section 17.12

© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.
Java How to Program, 5/e Test Item File 5 of 5

( No questions )

Section 17.13

17.13 Q1: Select the correct order:


a.position, limit, mark, capacity.
b.limit, capacity, mark, position.
c.mark, position, limit, capacity.
d.mark, limit, position, capacity.
ANS: c. mark, position, limit, capacity.

17.13 Q2: Which buffer operation sets the limit to the position and then sets the position to 0?
a.flip.
b.reset.
c.rewind.
d.clear.
ANS: a. flip.

17.13 Q3: Which of these statements is false?


a.Any two locks on the same file will overlap.
b.Method tryLock is a non-blocking operation while method lock is a blocking operation.
c.Shared locks allow overlapping shared locks, but no overlapping exclusive locks.
d.Exclusive locks allow no overlapping locks.
ANS: a. Any two locks on the same file will overlap.

17.13 Q4: Class Charset is declared in which package?


a.java.io.charset.
b.java.lang.charset.
c.javax.charset.
d.java.nio.charset.
ANS: d. java.nio.charset.

© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.

You might also like