Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

All of these are Java Questions. Please only answer if you are sure your answer

ID: 3697756 • Letter: A

Question

All of these are Java Questions. Please only answer if you are sure your answer is correct. Negative reviews will be given for incorrect answers.

1E.

Consider the following code snippet:

How can the program ensure that the file will be closed if an exception occurs on the writeData call?

Select one:

a. The program does not need to take any action, because the output file will be automatically closed when the exception occurs.

b. The program should place the outputFile.close() statement within a try block to ensure that the file will be closed.

c. It is not possible to ensure that the file will be closed when the exception occurs.

d. The program should place the outputFile.close() statement within a finally clause of a try block to ensure that the file is closed.

2E.

Consider the following code snippet:

Which of the following statements about this code is correct?

Select one:

a. This code will read in an entire line from the file in each iteration of the loop.

b. This code will read in the entire contents of the file in a single iteration of the loop.

c. This code will read in a single word from the file in each iteration of the loop.

d. This code will read in a single character from the file in each iteration of the loop.

3E.

hen writing a method, which of the following statements about exception handling is true?

Select one:

a. The throws clause must list all checked exceptions that this method may throw, and may also list unchecked exceptions.

b. The throws clause must list all unchecked exceptions, and may also list checked exceptions that this method may throw.

c. The throws clause must list all checked exceptions, but cannot list unchecked exceptions.

d. The throws clause must list all unchecked exceptions, and cannot list checked exceptions.

4E.

Insert the missing code in the following code fragment. This fragment is intended to read a file and write to a file.

Select one:

a. new PrintWriter(outputFileName)

b. new Scanner(outputFileName)

c. new PrintWriter(outputFile)

d. new Scanner(outputFile)

5E.

Which Java class implements a file dialog box for selecting a file by a program with a graphical user interface?

Select one:

a. JOptionPane

b. JFileOption

c. JFilePane

d. JFileChooser

Explanation / Answer

Answer for Question:

1E Answer is : Option D

the use of java finally block is :
Finally block in java can be used to put "cleanup" code such as closing a file, closing connection etc.

2E Answer is : Option A

hasNextline method will read the one line at a time and will check the next line is present or not

3E Answer is : Option C

The throws clause must list all checked exceptions, but cannot list unchecked exceptions.

4E Answer is :Option A

PrintWriter object will write the data to a file

a. new PrintWriter(outputFileName)

5E Answer is : Option D

JFileChooser is used to select the file