Deck 11: Exceptions and Advanced File Io

Full screen (f)
exit full mode
Question
When you deserialize an object using the readObject method, you must cast the return value to the desired class type.
Use Space or
up arrow
down arrow
to flip the card.
Question
Beginning with Java7, to catch multiple exceptions with a single catch, you can use __________.

A) multi-catch
B) catch templates
C) multi-try
D) catchAll
Question
A class must implement the Serializable interface in order for the objects of the class to be serialized.
Question
All of the exceptions you will handle are instances of classes that extend the __________ class.

A) RunTimeException
B) IOException
C) Error
D) Exception
Question
The throw statement informs the compiler that a method throws one or more exceptions.
Question
The ability to catch multiple types of exceptions with a single catch clause is known as multi-catch and was introduced in Java 7.
Question
The call stack is an internal list of all the methods that are currently executing.
Question
If the class SerializedClass contains references to objects of other classes as fields, those classes must also implement the Serializable interface in order to be serialized.
Question
When catching multiple exceptions that are related to one another through inheritance you should handle the more general exception classes before the more specialized exception classes.
Question
The throws clause causes an exception to be thrown.
Question
In a try statement, the try clause must appear first, followed by all of the catch clauses, followed by the optional finally clause.
Question
When you write a method that throws a checked exception, you must __________.

A) override the default error method
B) ensure that the error will occur at least once each time the program is executed
C) have a throws clause in the method header
D) use each class only once in a method
Question
The catch clause __________.

A) starts with the word catch followed by a parameter list in parentheses containing an ExceptionType parameter variable
B) follows the try clause
C) contains code to gracefully handle the exception type listed in the parameter list
D) The catch clause does all of these
Question
When an exception is thrown by a method that is executing under several layers of method calls, a stack trace indicates the method executing when an exception occurred and all of the methods that were called in order to execute that method.
Question
When the code in a try block may throw more than one type of exception, you need to write a catch clause for each type of exception that could potentially be thrown.
Question
When an object is serialized, it is converted into a series of bytes that contain the object's data.
Question
In versions of Java prior to Java 7 each catch clause could handle only one type of exception.
Question
When writing a string to a binary file or reading a string from a binary file, it is recommended that you use __________.

A) methods that use UTF-8 encoding
B) the FileReader and Writer class methods
C) the Scanner class methods
D) the System.In and System.out methods
Question
All exceptions are instances of classes that extend the __________ class.

A) RunTimeException
B) Throwable
C) Error
D) Exception
Question
A catch clause that uses a parameter variable of the Exception type is capable of catching any exception that extends the Error class.
Question
When an exception is thrown __________.

A) it must always be handled by the method that throws it
B) it must be handled by the program or by the default exception handler
C) it may be ignored
D) the program terminates even if the exception is handled
Question
To read data from a binary file, you create objects from which of the following classes?

A) File and Scanner
B) File and PrintWriter
C) BinaryFileReader and BinaryDataReader
D) FileInputStream and DataInputStream
Question
To write data to a binary file, you create objects from which of the following classes?

A) File and Scanner
B) BinaryFileWriter and BinaryDataWriter
C) FileOutputStream and DataOutputStream
D) File and PrintWriter
Question
A(n) __________ contains one or more statements that are executed and can potentially throw an exception.

A) exception block
B) catch block
C) try block
D) error block
Question
The try statement may have an optional __________ clause which must appear after all of the catch clauses.

A) try-again
B) finally
C) default
D) abort
Question
All of the exceptions that you will handle are instances of classes that extend the __________ class.

A) IOException
B) Exception
C) Error
D) RunTimeException
Question
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?

A) file.seek(4);
B) file.seek(8);
C) file.seek(10);
D) file.seek(5);
Question
In a try/catch construct, after the catch statement is executed __________.

A) the program returns to the statement following the statement in which the exception occurred
B) the program terminates
C) the program resumes at the statement that immediately follows the try/catch construct
D) the program resumes at the first statement of the try statement
Question
In Java there are two categories of exceptions which are __________.

A) unchecked and checked
B) runtime and compile-time
C) critical and nominal
D) static and dynamic
Question
An exception object's default error message can be retrieved using the __________ method.

A) getMessage
B) getDefaultMessage
C) getDefaultErrorMessage
D) getErrorMessage
Question
The numeric classes' parse methods all throw an exception of __________ type if the string being converted does not contain a convertible numeric value.

A) NumberFormatException
B) ParseIntException
C) ExceptionMessage
D) FileNotFoundException
Question
In order for an object to be serialized, its class must implement the __________ interface.

A) Serial
B) Serializable
C) ObjectOutputStream
D) Writeable
Question
A(n) __________ is a section of code that gracefully responds to exceptions when they are thrown.

A) exception
B) default exception handler
C) exception handler
D) thrown class
Question
A file that contains raw binary data is known as a __________.

A) binary file
B) machine file
C) serial file
D) raw data file
Question
In a multi-catch (introduced in Java 7) the exception types are separated in the catch clause by the __________ symbol.

A) *
B) ?
C) |
D) &
Question
If your code does not handle an exception when it is thrown, __________ prints an error message and crashes the program.

A) the Java error handler.
B) multi-catch
C) default exception handler
D) try statement
Question
An exception's default error message can be retrieved by using the __________ method.

A) getMessage()
B) getErrorMessage()
C) getDefaultMessage()
D) getDefaultErrorMessage()
Question
To serialize an object and write it to the file, use the __________ method of the ObjectOutputStream class.

A) WriteObject
B) SerializeObject
C) Serialize
D) SerializeAndWrite
Question
What happens if a program does not handle an unchecked exception?

A) This isn't possible; the program must handle the exception.
B) The program is halted and the default exception handler handles the exception.
C) The exception is ignored.
D) A compiler error will occur.
Question
A(n) __________ is an object that is generated in memory as the result of an error or an unexpected event.

A) exception
B) exception handler
C) default exception handler
D) error message
Question
Unchecked exceptions are those that inherit from the __________.

A) Error class or the RuntimeException class
B) Error class or the Exception class
C) Error class
D) ExceptionClass class or the RuntimeException class
Question
The IllegalArgumentException class extends the RuntimeException class and is, therefore, __________.

A) a checked exception class
B) an unchecked exception class
C) never used directly
D) None of these
Question
When using the throw statement, if you don't pass a message to the exception object's constructor, then __________.

A) the exception will have a null message
B) the exception will have a message containing the address of the exception
C) the exception will have a default message describing the exception
D) a compiler error will occur
Question
Classes that inherit from the Error class are for exceptions that are thrown when __________.

A) an IOException occurs, and the application program should not try to handle them
B) a critical error occurs, and the application program should not try to handle them
C) an IOException occurs, and the application program should try to handle them
D) a critical error occurs, and the application program should try to handle them
Question
The following catch statement can __________. catch (Exception e) {...}

A) handle all throwable objects by using a polymorphic reference for the parameter
B) handle all exceptions that are instances of the Exception class or one of its subclasses
C) handle all exceptions that are instances of the Exception class but not its subclasses
D) cause a compiler error
Question
If a method does not handle a possible checked exception, what must the method have?

A) a try clause in its header
B) a catch clause in its header
C) a finally clause in its header
D) a throws clause in its header
Question
When an exception is thrown by code in its try block, the JVM begins searching the try statement for a catch clause that can handle it and passes control of the program to __________.

A) the last catch clause that can handle the exception
B) each catch clause that can handle the exception
C) the first catch clause that can handle the exception
D) the statement that appears immediately after the catch block
Question
What will be the result of the following statements? FileOutputStream fstream = new FileOutputStream("Output.dat");
DataOutputStream outputFile = new DataOutputStream(fstream);

A) The outputFile variable will reference an object that is able to write text data only to the Output.dat file.
B) The outputFile variable will reference an object that is able to write binary data to the Output.dat file.
C) The outputFile variable will reference an object that is able to read binary data from the Output.dat file.
D) The outputFile variable will reference an object that is able to write binary data to the Output.dat as a random access file.
Question
In a catch statement, what does the following code do? System.out.println(e.getMessage());

A) It prints the code that caused the exception.
B) It prints the stack trace.
C) It prints the error message for an exception.
D) It overrides the toString method.
Question
Assume that the classes BlankISBN, NegativePrice, and NegativeNumberOrdered are exception classes that inherit from Exception. The following code is a constructor for the Book class. What must be true about any method that instantiates the Book class with this constructor? public Book(String ISBNOfBook, double priceOfBook,
Int numberOrderedOfBook)
{
If (ISBNOfBook == "")
Throw new BlankISBN();
If (priceOfBook < 0)
Throw new NegativePrice(priceOfBook);
If (numberedOrderedOfBook < 0)
Throw new NegativeNumberOrdered(numberOrderedv);
ISBN = ISBNOfBook;
Price = priceOfBook;
NumberedOrdered = numberOrderedOfBook;
}

A) It must call the constructor with valid data or a compiler error will occur.
B) It must contain an inner class that extends the IOException class.
C) It must handle all of the possible exceptions thrown by the constructor or have its own throws clause specifying them.
D) All of these are true.
Question
What will be the result of the following statements? FileInputStream fstream = new FileInputStream("Input.dat");
DataInputStream inFile = new DataInputStream(fstream);

A) The inFile variable will reference an object that is able to read random access data from the Input.dat file.
B) The inFile variable will reference an object that is able to read text data from the Input.dat file.
C) The inFile variable will reference an object that is able to read binary data from the Input.dat file.
D) The inFile variable will reference an object that is able to write binary data to the Input.dat file.
Question
Given the following constructor code, which of the statements are true? public Book(String ISBNOfBook, double priceOfBook,
Int numberOrderedOfBook)
{
If (ISBNOfBook == "")
Throw new BlankISBN();
If (priceOfBook < 0)
Throw new NegativePrice(priceOfBook);
If (numberedOrderedOfBook < 0)
Throw new NegativeNumberOrdered(numberOrderedv);
ISBN = ISBNOfBook;
Price = priceOfBook;
NumberedOrdered = numberOrderedOfBook;
}

A) There is an error: a throws clause should be added to the constructor header.
B) Classes extending the Exception class should be created for each of the custom exceptions that are thrown in the constructor.
C) A FileNotFoundException will be thrThe calling method must handle the exceptions thrown in the constructor, or have its own throws clause specifying them.
D) All of these are true.
Question
If you want to append data to an existing binary file, BinaryFile.dat, which of the following statements would you use to open the file?

A) FileOutputStream fstream =
New FileOutputStream("BinaryFile.dat");
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream);
B) FileOutputStream fstream =
New FileOutputStream("BinaryFile.dat", false);
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream);
C) FileOutputStream fstream =
New FileOutputStream("BinaryFile.dat", true);
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream);
D) IFileOutputStream fstream =
New FileOutputStream("BinaryFile.dat");
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream, true);
Question
If the data.dat file does not exist, what will happen when the following statement is executed? RandomAccessFile randomFile = new RandomAccessFile("data.dat", "rw");

A) An IOException will be thrown.
B) The file, data.dat, will be created.
C) A FileNotFoundException will be thrown.
D) A compiler error will occur.
Question
In Windows, which of the following statements will open the file, InputFile.txt, that is in the root directory on the C: drive?

A) FileReader freader = new FileReader("C:\InputFile.txt");
B) FileReader freader = new FileReader("C:\InputFile\txt");
C) FileReader freader = new FileReader("/c/InputFile.txt");
D) FileReader freader = new FileReader("C:\\InputFile.txt");
Question
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

A) 19.5.
B) 0.0
C) 35.5
D) 75.0
Question
The RandomAccessFile class treats a file as a stream of __________.

A) bytes
B) characters
C) integers
D) data
Question
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);

A) -1
B) 0
C) 1
D) 99
Question
If the code in a method can potentially throw a checked exception, then that method must __________.

A) handle the exception
B) have a throws clause listed in the method header
C) neither of these
D) either of these
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/59
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 11: Exceptions and Advanced File Io
1
When you deserialize an object using the readObject method, you must cast the return value to the desired class type.
True
2
Beginning with Java7, to catch multiple exceptions with a single catch, you can use __________.

A) multi-catch
B) catch templates
C) multi-try
D) catchAll
A
3
A class must implement the Serializable interface in order for the objects of the class to be serialized.
True
4
All of the exceptions you will handle are instances of classes that extend the __________ class.

A) RunTimeException
B) IOException
C) Error
D) Exception
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
5
The throw statement informs the compiler that a method throws one or more exceptions.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
6
The ability to catch multiple types of exceptions with a single catch clause is known as multi-catch and was introduced in Java 7.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
7
The call stack is an internal list of all the methods that are currently executing.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
8
If the class SerializedClass contains references to objects of other classes as fields, those classes must also implement the Serializable interface in order to be serialized.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
9
When catching multiple exceptions that are related to one another through inheritance you should handle the more general exception classes before the more specialized exception classes.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
10
The throws clause causes an exception to be thrown.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
11
In a try statement, the try clause must appear first, followed by all of the catch clauses, followed by the optional finally clause.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
12
When you write a method that throws a checked exception, you must __________.

A) override the default error method
B) ensure that the error will occur at least once each time the program is executed
C) have a throws clause in the method header
D) use each class only once in a method
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
13
The catch clause __________.

A) starts with the word catch followed by a parameter list in parentheses containing an ExceptionType parameter variable
B) follows the try clause
C) contains code to gracefully handle the exception type listed in the parameter list
D) The catch clause does all of these
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
14
When an exception is thrown by a method that is executing under several layers of method calls, a stack trace indicates the method executing when an exception occurred and all of the methods that were called in order to execute that method.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
15
When the code in a try block may throw more than one type of exception, you need to write a catch clause for each type of exception that could potentially be thrown.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
16
When an object is serialized, it is converted into a series of bytes that contain the object's data.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
17
In versions of Java prior to Java 7 each catch clause could handle only one type of exception.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
18
When writing a string to a binary file or reading a string from a binary file, it is recommended that you use __________.

A) methods that use UTF-8 encoding
B) the FileReader and Writer class methods
C) the Scanner class methods
D) the System.In and System.out methods
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
19
All exceptions are instances of classes that extend the __________ class.

A) RunTimeException
B) Throwable
C) Error
D) Exception
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
20
A catch clause that uses a parameter variable of the Exception type is capable of catching any exception that extends the Error class.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
21
When an exception is thrown __________.

A) it must always be handled by the method that throws it
B) it must be handled by the program or by the default exception handler
C) it may be ignored
D) the program terminates even if the exception is handled
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
22
To read data from a binary file, you create objects from which of the following classes?

A) File and Scanner
B) File and PrintWriter
C) BinaryFileReader and BinaryDataReader
D) FileInputStream and DataInputStream
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
23
To write data to a binary file, you create objects from which of the following classes?

A) File and Scanner
B) BinaryFileWriter and BinaryDataWriter
C) FileOutputStream and DataOutputStream
D) File and PrintWriter
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
24
A(n) __________ contains one or more statements that are executed and can potentially throw an exception.

A) exception block
B) catch block
C) try block
D) error block
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
25
The try statement may have an optional __________ clause which must appear after all of the catch clauses.

A) try-again
B) finally
C) default
D) abort
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
26
All of the exceptions that you will handle are instances of classes that extend the __________ class.

A) IOException
B) Exception
C) Error
D) RunTimeException
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
27
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?

A) file.seek(4);
B) file.seek(8);
C) file.seek(10);
D) file.seek(5);
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
28
In a try/catch construct, after the catch statement is executed __________.

A) the program returns to the statement following the statement in which the exception occurred
B) the program terminates
C) the program resumes at the statement that immediately follows the try/catch construct
D) the program resumes at the first statement of the try statement
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
29
In Java there are two categories of exceptions which are __________.

A) unchecked and checked
B) runtime and compile-time
C) critical and nominal
D) static and dynamic
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
30
An exception object's default error message can be retrieved using the __________ method.

A) getMessage
B) getDefaultMessage
C) getDefaultErrorMessage
D) getErrorMessage
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
31
The numeric classes' parse methods all throw an exception of __________ type if the string being converted does not contain a convertible numeric value.

A) NumberFormatException
B) ParseIntException
C) ExceptionMessage
D) FileNotFoundException
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
32
In order for an object to be serialized, its class must implement the __________ interface.

A) Serial
B) Serializable
C) ObjectOutputStream
D) Writeable
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
33
A(n) __________ is a section of code that gracefully responds to exceptions when they are thrown.

A) exception
B) default exception handler
C) exception handler
D) thrown class
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
34
A file that contains raw binary data is known as a __________.

A) binary file
B) machine file
C) serial file
D) raw data file
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
35
In a multi-catch (introduced in Java 7) the exception types are separated in the catch clause by the __________ symbol.

A) *
B) ?
C) |
D) &
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
36
If your code does not handle an exception when it is thrown, __________ prints an error message and crashes the program.

A) the Java error handler.
B) multi-catch
C) default exception handler
D) try statement
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
37
An exception's default error message can be retrieved by using the __________ method.

A) getMessage()
B) getErrorMessage()
C) getDefaultMessage()
D) getDefaultErrorMessage()
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
38
To serialize an object and write it to the file, use the __________ method of the ObjectOutputStream class.

A) WriteObject
B) SerializeObject
C) Serialize
D) SerializeAndWrite
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
39
What happens if a program does not handle an unchecked exception?

A) This isn't possible; the program must handle the exception.
B) The program is halted and the default exception handler handles the exception.
C) The exception is ignored.
D) A compiler error will occur.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
40
A(n) __________ is an object that is generated in memory as the result of an error or an unexpected event.

A) exception
B) exception handler
C) default exception handler
D) error message
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
41
Unchecked exceptions are those that inherit from the __________.

A) Error class or the RuntimeException class
B) Error class or the Exception class
C) Error class
D) ExceptionClass class or the RuntimeException class
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
42
The IllegalArgumentException class extends the RuntimeException class and is, therefore, __________.

A) a checked exception class
B) an unchecked exception class
C) never used directly
D) None of these
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
43
When using the throw statement, if you don't pass a message to the exception object's constructor, then __________.

A) the exception will have a null message
B) the exception will have a message containing the address of the exception
C) the exception will have a default message describing the exception
D) a compiler error will occur
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
44
Classes that inherit from the Error class are for exceptions that are thrown when __________.

A) an IOException occurs, and the application program should not try to handle them
B) a critical error occurs, and the application program should not try to handle them
C) an IOException occurs, and the application program should try to handle them
D) a critical error occurs, and the application program should try to handle them
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
45
The following catch statement can __________. catch (Exception e) {...}

A) handle all throwable objects by using a polymorphic reference for the parameter
B) handle all exceptions that are instances of the Exception class or one of its subclasses
C) handle all exceptions that are instances of the Exception class but not its subclasses
D) cause a compiler error
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
46
If a method does not handle a possible checked exception, what must the method have?

A) a try clause in its header
B) a catch clause in its header
C) a finally clause in its header
D) a throws clause in its header
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
47
When an exception is thrown by code in its try block, the JVM begins searching the try statement for a catch clause that can handle it and passes control of the program to __________.

A) the last catch clause that can handle the exception
B) each catch clause that can handle the exception
C) the first catch clause that can handle the exception
D) the statement that appears immediately after the catch block
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
48
What will be the result of the following statements? FileOutputStream fstream = new FileOutputStream("Output.dat");
DataOutputStream outputFile = new DataOutputStream(fstream);

A) The outputFile variable will reference an object that is able to write text data only to the Output.dat file.
B) The outputFile variable will reference an object that is able to write binary data to the Output.dat file.
C) The outputFile variable will reference an object that is able to read binary data from the Output.dat file.
D) The outputFile variable will reference an object that is able to write binary data to the Output.dat as a random access file.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
49
In a catch statement, what does the following code do? System.out.println(e.getMessage());

A) It prints the code that caused the exception.
B) It prints the stack trace.
C) It prints the error message for an exception.
D) It overrides the toString method.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
50
Assume that the classes BlankISBN, NegativePrice, and NegativeNumberOrdered are exception classes that inherit from Exception. The following code is a constructor for the Book class. What must be true about any method that instantiates the Book class with this constructor? public Book(String ISBNOfBook, double priceOfBook,
Int numberOrderedOfBook)
{
If (ISBNOfBook == "")
Throw new BlankISBN();
If (priceOfBook < 0)
Throw new NegativePrice(priceOfBook);
If (numberedOrderedOfBook < 0)
Throw new NegativeNumberOrdered(numberOrderedv);
ISBN = ISBNOfBook;
Price = priceOfBook;
NumberedOrdered = numberOrderedOfBook;
}

A) It must call the constructor with valid data or a compiler error will occur.
B) It must contain an inner class that extends the IOException class.
C) It must handle all of the possible exceptions thrown by the constructor or have its own throws clause specifying them.
D) All of these are true.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
51
What will be the result of the following statements? FileInputStream fstream = new FileInputStream("Input.dat");
DataInputStream inFile = new DataInputStream(fstream);

A) The inFile variable will reference an object that is able to read random access data from the Input.dat file.
B) The inFile variable will reference an object that is able to read text data from the Input.dat file.
C) The inFile variable will reference an object that is able to read binary data from the Input.dat file.
D) The inFile variable will reference an object that is able to write binary data to the Input.dat file.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
52
Given the following constructor code, which of the statements are true? public Book(String ISBNOfBook, double priceOfBook,
Int numberOrderedOfBook)
{
If (ISBNOfBook == "")
Throw new BlankISBN();
If (priceOfBook < 0)
Throw new NegativePrice(priceOfBook);
If (numberedOrderedOfBook < 0)
Throw new NegativeNumberOrdered(numberOrderedv);
ISBN = ISBNOfBook;
Price = priceOfBook;
NumberedOrdered = numberOrderedOfBook;
}

A) There is an error: a throws clause should be added to the constructor header.
B) Classes extending the Exception class should be created for each of the custom exceptions that are thrown in the constructor.
C) A FileNotFoundException will be thrThe calling method must handle the exceptions thrown in the constructor, or have its own throws clause specifying them.
D) All of these are true.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
53
If you want to append data to an existing binary file, BinaryFile.dat, which of the following statements would you use to open the file?

A) FileOutputStream fstream =
New FileOutputStream("BinaryFile.dat");
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream);
B) FileOutputStream fstream =
New FileOutputStream("BinaryFile.dat", false);
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream);
C) FileOutputStream fstream =
New FileOutputStream("BinaryFile.dat", true);
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream);
D) IFileOutputStream fstream =
New FileOutputStream("BinaryFile.dat");
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream, true);
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
54
If the data.dat file does not exist, what will happen when the following statement is executed? RandomAccessFile randomFile = new RandomAccessFile("data.dat", "rw");

A) An IOException will be thrown.
B) The file, data.dat, will be created.
C) A FileNotFoundException will be thrown.
D) A compiler error will occur.
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
55
In Windows, which of the following statements will open the file, InputFile.txt, that is in the root directory on the C: drive?

A) FileReader freader = new FileReader("C:\InputFile.txt");
B) FileReader freader = new FileReader("C:\InputFile\txt");
C) FileReader freader = new FileReader("/c/InputFile.txt");
D) FileReader freader = new FileReader("C:\\InputFile.txt");
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
56
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

A) 19.5.
B) 0.0
C) 35.5
D) 75.0
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
57
The RandomAccessFile class treats a file as a stream of __________.

A) bytes
B) characters
C) integers
D) data
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
58
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);

A) -1
B) 0
C) 1
D) 99
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
59
If the code in a method can potentially throw a checked exception, then that method must __________.

A) handle the exception
B) have a throws clause listed in the method header
C) neither of these
D) either of these
Unlock Deck
Unlock for access to all 59 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 59 flashcards in this deck.