Chapter 11

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Unchecked exceptions are those that inherit from the ________.

Error class or the RuntimeException class

What will the following code display? String input = "99#7"; int number;try{number = Integer.parseInt(input); } catch(NumberFormatException ex) { number = 0; } catch(RuntimeException ex) { number = 1; } catch(Exception ex) { number = -1; } System.out.println(number);

0

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

Exception

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

Exception

To read data from a binary file, you create objects from which of the following classes?

FileInputStream and DataInputStream

To write data to a binary file, you create objects from which of the following classes?

FileOutputStream and DataOutputStream

In Windows, which of the following statements will open the file, InputFile.txt, that is in the root directory on the C: drive? FileReader freader = new FileReader("/c/InputFile.txt"); FileReader freader = new FileReader("C:\InputFile.txt"); FileReader freader = new FileReader("C:\\InputFile.txt"); FileReader freader = new FileReader("C:\InputFile\txt");

FileReader freader = new FileReader("C:\\InputFile.txt");

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

It prints the error message for an exception.

The numeric classes' parse methods all throw an exception of ________ type if the string being converted does not contain a convertible numeric value.

NumberFormatException

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

Serializable

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

WriteObject

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

a throws clause in its header

The IllegalArgumentException class extends the RuntimeException class and is, therefore, ________.

an unchecked exception class

The RandomAccessFile class treats a file as a stream of ________.

bytes

A(n) ________ is a section of code that gracefully responds to exceptions when they are thrown.

exception handler

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

The try statement may have an optional ________ clause which must appear after all of the catch clauses.

finally

An exception's default error message can be retrieved by using the ________ method.

getMessage()

In Java there are two categories of exceptions which are ________.

unchecked and checked

In a multi-catch (introduced in Java 7) the exception types are separated in the catch clause by the ________ symbol.

|

In the following code, assume that inputFile references a Scanner object that has been successfully used to open a file: double totalIncome = 0.0; while (inputFile.hasNext()) { try { totalIncome += inputFile.nextDouble(); } catch(InputMismatchException e) { System.out.println("Non-numeric data encountered " +"in the file."); inputFile.nextLine(); } finally { totalIncome = 35.5; } } What will be the value of totalIncome after the following values are read from the file? 2.5 8.5 3.0 5.5 abc 1.0

35.5

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

The file, data.dat, will be created.

All exceptions are instances of classes that extend the ________ class.

Throwable

A file that contains raw binary data is known as a ________.

binary file

If the code in a method can potentially throw a checked exception, then that method must ________.

either handle the exception or have a throws clause listed in the method header

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

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

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 binary data from the Input.dat file.

What will be the result of the following statements? FileOutputStream fstream = new FileOutputStream("Output.dat"); DataOutputStream outputFile = new DataOutputStream(fstream);

The outputFile variable will reference an object that is able to write binary data to the Output.dat file.


संबंधित स्टडी सेट्स

COPD (emphysema & chronic bronchitis)

View Set

46.5 The Ecological Framework of Biodiversity

View Set

Evaluating Functions instruction

View Set

MED SURG 1- PrepU Chapter 28: Assessment of Hematologic Function and Treatment Modalities

View Set

Legal Dimensions of Nursing Practice (Jenny VanOverstraeten)

View Set

BIO 102-Chapter 30: The Respiratory System

View Set

Brunner-Suddarth Med-Surg 13th Ed. Ch. 67

View Set