Ch. 10

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

If the data.dat file does not exist, what will happen when the following statement is executed? RandomAccessFile randomFile = new RandomAccessFile("data.dat", "rw");

An IOExcepton will be thrown. - wrong A compiler error will occur. - wrong

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"));

The RandomAccessFile class treats a file as a stream of

bytes.

To write data to a binary file, you create objects from the following classes:

File and Scanner. - wrong BinaryFileWriter and BinaryDataWriter. - wrong

All of the exceptions that you will handle are instances of classes that extend this class.

IOException - wrong

In a catch statement, what does the following code do? System.out.println(e.getMessage());

It prints the code that caused the exception. - wrong It prints the stack trace. - wrong

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

Serial - wrong ObjectOutputStream - wrong

What will be the result of the following statements? FileInputStream fstream = new FileInputStream("Input.dat"); DataInputStream inFile = new DataInputStream(fstream);

The inFile variable will reference an object that is able to read random access data from the Input.dat file. - wrong The inFile variable will reference an object that is able to read text data from the Input.dat file. - wrong

When you deserialize an object using the readObject method, you must cast the return value to the desired class type.

True

To serialize an object and write it to the file, use this method of the ObjectOutputStream class.

WriteObject

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

a try clause in its header - wrong

A file that contains raw binary data is known as a(n)

binary file.

The following catch clause catch (Exception e)

can handle all exceptions that are instances of the Exception class or one of its subclasses.

A(n) ________ is an object that is generated in memory as the result of an error or an unexpected event.

exception

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

exception block - wrong catch block - wrong

The throw statement informs the compiler that a method throws one or more exception.

false

The throws clause causes an exception to be thrown.

false

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(4); - wrong file.seek(5); - wrong

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.

When you write a method that throws a checked exception, you must

override the default error method. - wrong

The catch clause

starts with the word catch followed by a parameter list in parentheses containing an ExceptionType parameter variable. follows the try clause. contains code to gracefully handle the exception type listed in the parameter list. All of these

When using the throw statement, if you do not pass a message to the exception object's constructor,

the exception will have a null message.

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 last catch clause that can handle the exception. - wrong each catch clause that can handle the exception. - wrong

A class must implement the Serializable interface in order for objects of the class to be serialized.

true

If a class has fields that are objects of other classes, those classes must implement the Serializable interface in order to be serialized.

true

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

true

The ability to catch multiple types of exceptions with a single catch clause is known as multi-catch, and was introduced in Java 7.

true

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

true

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

When you deserialize an object using the readObject method, you must cast the return value to the desired class type.

true

Unchecked exceptions are those that inherit from the

Error class or the RuntimeException class.

In Java, there are two categories of exceptions:

unchecked and checked.


Ensembles d'études connexes

Educational Technology for Teaching and Learning

View Set

RA 1378 Water Supply Fixture Units (Table 6-5)

View Set

2.5.7 - PC Maintenance - Practice Questions

View Set