Exam 11: Inputoutput and Exception Handling

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

Insert the missing code in the following code fragment. This fragment is intended to read binary data. public static void main(String[] args) throws IOException { String address = "http://horstmann.com/bigjava.gif"; URL imageLocation = _________; InputStream in = imageLocation.openStream()); ) . . }

(Multiple Choice)
4.8/5
(31)

Consider the following code snippet: Scanner in = new Scanner(. . .); While (in.hasNextInt()) { ) . . } Under which condition will the body of the while loop be processed?

(Multiple Choice)
4.9/5
(29)

Assuming that inputFile is a Scanner object used to read words from a text file, select an expression to complete the following code segment, which counts the number of words in the input file. Int count = 0; While (inputFile.hasNext()) { String word = _______________; Count++; } System.out.println(count);

(Multiple Choice)
4.7/5
(37)

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
(40)

Which statement about handling exceptions is true?

(Multiple Choice)
4.8/5
(41)

The ____ method of the Character class will indicate if a character contains white space.

(Multiple Choice)
4.9/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.9/5
(33)

Insert the missing code in the following code fragment. This code is intended to open a file and handle the situation where the file cannot be found. try { String filename = . . .; Scanner in = new Scanner(new File(filename)); ) . . } ___________________ { Exception.printStackTrace(); }

(Multiple Choice)
5.0/5
(45)

Which of the following statements about using a PrintWriter object is NOT true?

(Multiple Choice)
4.7/5
(36)

Consider the following code snippet. Scanner inputFile = new Scanner("dataIn.txt"); Which of the following statements is correct?

(Multiple Choice)
4.9/5
(46)

Which of the following statements about exception handling is correct?

(Multiple Choice)
4.9/5
(42)

Insert the missing code in the following code fragment. This fragment is intended to read a web page. public static void main(String[] args) throws IOException { String address = "http://horstmann.com/index.html"; URL pageLocation = new URL(address); Scanner in = _________; ) . . }

(Multiple Choice)
4.8/5
(36)

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.8/5
(42)

Which String class method will remove spaces from the beginning and the end of a string?

(Multiple Choice)
4.9/5
(36)

Insert the missing code in the following code fragment. This fragment is intended to read a file and write to a file. public static void main(String[] args) throws FileNotFoundException { String inputFileName = "dataIn.txt"; String outputFileName = "dataOut.txt"; File inputFile = new File(inputFileName); Scanner in = new Scanner(inputFile); PrintWriter out = _____________; ) . . }

(Multiple Choice)
5.0/5
(32)

Your program must read in an existing text file. You want the program to terminate if the file does not exist. Which of the following indicates the correct code for the main method header?

(Multiple Choice)
4.7/5
(31)

Which of the following code snippets about exceptions is correct?

(Multiple Choice)
4.9/5
(46)

Consider the following code snippet: try { File inputFile = new File(filename); Scanner in = new Scanner(inputFile); ) . . } Catch (Exception

(Multiple Choice)
5.0/5
(35)

Assume that inputFile is a Scanner object used to read data from a text file which contains a series of double values. Select an expression to complete the following code segment, which reads the values and prints them in standard output, one per line, in a field 15 characters wide, with two digits after the decimal point. while (inputFile.hasNextDouble()) { Double value = inputFile.nextDouble(); ___________________________________ // statement do display double value }

(Multiple Choice)
4.9/5
(44)

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

(Multiple Choice)
5.0/5
(39)
Showing 21 - 40 of 109
close modal

Filters

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