Exam 7: Inputoutput and Exception Handling

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

Your program must read in an existing text file. You want the program to terminate if any exception related to the file occurs. Which of the following indicates the correct code for the main method?

(Multiple Choice)
4.9/5
(36)

Which method of the JFileChooser object will return the file object that describes the file chosen by the user at runtime?

(Multiple Choice)
4.9/5
(30)

Insert the missing code in the following code fragment. This fragment is intended to read an input file. Public static void main(String[] args) throws FileNotFoundException { String inputFileName = "dataIn.txt"; String outputFileName = "dataOut.txt"; File inputFile = new File(inputFileName); Scanner in = _______________; ) . . }

(Multiple Choice)
4.9/5
(33)

In the hierarchy of Exception classes, the NumberFormatException class is a subclass of the ____ class.

(Multiple Choice)
4.8/5
(35)

Consider the following code snippet: Scanner in = new Scanner(. . .); ) . . If (in.hasNext()) { Throw new IOException("End of file expected"); } Which of the following statements about this code is correct?

(Multiple Choice)
4.7/5
(30)

Which method of an exception object will provide information about the chain of method calls that led to the exception?

(Multiple Choice)
4.8/5
(47)

Consider the following code snippet: PrintWriter out = new PrintWriter("output.txt"); Which of the following statements about the PrintWriter object is correct?

(Multiple Choice)
4.8/5
(42)

Consider the following code snippet: Throw IllegalStateException("This operation is not allowed!"); Which of the following statements about this code is correct?

(Multiple Choice)
4.7/5
(38)

Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt and write to an output file named dataOut.txt. Public static void main(String[] args) throws FileNotFoundException { String inputFileName = "dataIn.txt"; String outputFileName = "dataOut.txt"; File inputFile = new File(inputFileName); Scanner in = _________; ) . . }

(Multiple Choice)
4.8/5
(33)

Consider the following code snippet: Try { PrintWriter outFile = new PrintWriter(filename); WriteData(outputFile); } Catch (IOException exception) { ) . . } Finally { OutputFile.close(); } What is wrong with this code?

(Multiple Choice)
4.9/5
(28)

Consider the following code snippet: Try { File inputFile = new File(filename); Scanner in = new Scanner(inputFile); ) . . } Catch (Exception e) { } Which of the following statements about this code is correct?

(Multiple Choice)
4.9/5
(44)

Which of the following code snippets about exceptions is correct?

(Multiple Choice)
4.8/5
(33)

Consider the following code snippet: System.out.printf("%-12s%8.2f",description,totalPrice); Which of the following statements is correct?

(Multiple Choice)
4.7/5
(37)

Insert the missing code in the following code fragment. This fragment is intended to read characters from a text file. Scanner in = new Scanner(. . .); In)useDelimiter(""); While (in.hasNext()) { Char ch = ____________; System.out.println(ch); }

(Multiple Choice)
4.9/5
(40)

Consider the following code snippet: Scanner in = new Scanner(. . .); String result = ""; Int number = 0; If (in.hasNextInt()) { Number = in.nextInt(); } Result = in.next(); If the input begins with the characters 626.14 average, what values will number and result have after this code is executed?

(Multiple Choice)
5.0/5
(43)

You have opened a command prompt window and you have entered the following: Java myProg Bob Smith Which of the following statements is correct?

(Multiple Choice)
4.8/5
(40)

Consider the following code snippet: Throw new IllegalArgumentException("This operation is not allowed!"); Which of the following statements about this code is correct?

(Multiple Choice)
4.8/5
(39)

Which of the following statements reflects the textbook's recommendations about closing files?

(Multiple Choice)
4.8/5
(35)

Which method of an exception object will retrieve a description of the exception that occurred?

(Multiple Choice)
4.8/5
(32)

Insert the missing code in the following code fragment. This fragment is intended to read floating-point numbers from a text file. Scanner in = new Scanner(. . .); While (____________) { Double hoursWorked = in.nextDouble(); System.out.println(hoursWorked); }

(Multiple Choice)
4.8/5
(46)
Showing 21 - 40 of 100
close modal

Filters

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