CH 11. Pt 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

If a method does not handle a possible checked exception, what must the method have?

a throws clause in its header

The RandomAccessFile class treats a file as a stream of

bytes

If a random access file contains a stream of characters, which of the following statements would move the file pointer to the starting byte of the fifth character in the file?

file.seek(8);

When an exception is thrown,

it must be handled by the program or by the default exception handler.

When writing a string to a binary file or reading a string from a binary file, it is recommended that you use

methods that use UTF-8 encoding

In order for an object to be serialized, the class must implement this interface.

serializable

When an exception is thrown by code in the try block, the JVM begins searching the try statement for a catch clause that can handle it and passes control of the program to

the first catch clause that can handle the exception.

A(n) ________ is one or more statements that are executed and can potentially throw an exception.

try block

In a catch statement, what does the following code do?

It prints the error message for an exception.

This is a section of code that gracefully responds to exceptions when they are thrown.

exception handler

Classes that inherit from the Error class are

for exceptions that are thrown when a critical error occurs, and the application program should not try to handle them.

The catch clause:

All of the above i. starts with the word catch followed by a parameter list in parentheses containing anExceptionType parameter variable. ii. contains code to gracefully handle the exception type listed in the parameter list. iii. follows the try clause

Look at the following code: FileInputStream fstream = new FileInputStream("info.dat"); DataInputStream inputFile = new DataInputStream(fstream); This code could also be written as

DataInputStream inputFile = new DataInputStream(new FileInputStream("info.dat"));

An exception object's default error message can be retrieved using this method.

getMessage

Beginning in Java 7, you can use ________ to reduce a lot of duplicated code in a try statement that needs to catch multiple exceptions, but perform the same operation for each one.

multi-catch

In a try statement, the try clause must appear first, followed by all of the catch clauses, followed by the optional finally clause.

true

T/F A class must implement the Serializable interface in order for objects of the class to be serialized

true

T/F The call stack is an internal list of all the methods that are currently executing.

true

T/F When an object is serialized, it is converted into a series of bytes that contain the object's data.

true

When catching multiple exceptions that are related to one another through inheritance, you should handle the more specialized exception classes before the more general exception classes.

true


Conjuntos de estudio relacionados

Work and Energy Practice Questions

View Set

Systems of Linear Equations in Three Variables

View Set

Population Genetics and Evolution

View Set