Exam 11: Exceptions, and Input Output Operations

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Code that could generate an unchecked exception must be coded with a try and catch block.

Free
(True/False)
4.9/5
(33)
Correct Answer:
Verified

False

PrintWriter( File f) throws a FileNotFoundException.

Free
(True/False)
4.7/5
(45)
Correct Answer:
Verified

True

A variable declared inside a try block is still in scope after we exit that try block.

Free
(True/False)
4.9/5
(28)
Correct Answer:
Verified

False

When we read objects from a file using the readObject method, what happens when the end of the file is reached?

(Essay)
4.8/5
(38)

Java provides classes and methods to read data from a remote file (located somewhere on the Internet).

(True/False)
5.0/5
(42)

Why it is important to place the catch clause with the EOFException ahead of the catch clause with the IOException?

(Multiple Choice)
4.7/5
(30)

Which of the following methods in the Exception classes returns void?

(Multiple Choice)
4.7/5
(34)

When we open a file for writing and the file does not exist, what will happen?

(Multiple Choice)
4.9/5
(34)

You want to handle a suspected exception in your program, so you insert the following try and catch blocks. However, the program generated a compiler error. Improve this program to avoid that problem. 1 2 try 3 { 4 n = Integer.parseInt( s ); 5 System.out.println( "Conversion was successful." ); 6 catch ( NumberFormatException nfe ) 7 System.out.println( "Sorry. incompatible data." ); 8 System.out.println( "\nOutput from getMessage: \n" 9 + nfe.getMessage( ) ); 10 11 System.out.println( "\nOutput from toString: \n" 12 + nfe.toString( ) ); 13 System.out.println( "\nOutput from printStackTrace: " ); 14 nfe.printStackTrace( ); 15 }

(Essay)
4.9/5
(38)

It is preferable to place data items from a file in an ArrayList object instead of a fixed-length array when you do not know how many lines are in the file.

(True/False)
4.7/5
(44)

What is a token?

(Multiple Choice)
4.8/5
(25)

The filter method of the DoubleStream interface has the following API, DoubleStream filter( DoublePredicate predicate ). What is DoublePredicate?

(Multiple Choice)
4.9/5
(46)

Handling a possible illegal operation with a try and catch block will make the code run faster than handling it with a simple if/else construct.

(True/False)
4.8/5
(39)

To correct this segment, line 12 should be changed to int n = 1;. 10 public static void main( String [ ] args ) 11 { 12 int n; 13 String s = JOptionPane.showInputDialog( null, 14 "Enter an integer" ); 15 System.out.println( "You entered " + s ); 16 17 try 18 { 19 n = Integer.parseInt( s ); 20 System.out.println( "Conversion was successful." ); 21 }

(True/False)
4.9/5
(37)

Melanie writes some code with the public class EmailChecker. She uses try and catch blocks to catch thrown exceptions. A user enters this email address: Javalovre@sw.com. Which of the following is a likely outcome?

(Multiple Choice)
4.8/5
(37)

Because the readObject method returns a generic object, what must the returned object be?

(Essay)
4.9/5
(42)

Which technique is often used when processing a Stream-in particular, calling several methods in order to process the data in the Stream?

(Multiple Choice)
4.9/5
(39)

Java does not allow objects to be written to or read from a file.

(True/False)
4.8/5
(33)

When an object is written to a file, transient instance variables of that object are not written to the file.

(True/False)
4.8/5
(33)

At run time, if a non-integer is entered, the call to the parseInt method will generate a(n):

(Multiple Choice)
4.9/5
(39)
Showing 1 - 20 of 77
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)