Question: These are all Java questions. Please only post if you can answer al questions and are sure your answers are correct. Negative reviews will be

These are all Java questions. Please only post if you can answer al questions and are sure your answers are correct. Negative reviews will be given for incorrect answers.

16.

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 = _______________; 
 . . . 
} 

Select one:

a. new Scanner(inputFileName)

b. new Scanner(outputFileName)

c. new Scanner(inputFile)

d. new Scanner(System.in)

17.

Consider the following code snippet:

public static void main(String[] args) throws IOException 

Which of the following statements about this code is correct?

Select one:

a. The main method is designed to catch and handle all types of exceptions.

b. The main method is designed to catch and handle the IOException.

c. The main method should simply terminate if the IOException occurs.

d. The main method will not terminate if any exception occurs.

18.

Which of the following is the correct syntax for starting a Java program named myProg from a command line if the program requires two arguments named arg1 and arg2 to be supplied?

Select one:

a. java myProg arg1 arg2

b. java myProg(arg1, arg2)

c. java myProg "arg1" "arg2"

d. java myProg arg1, arg2

19.

If the current method in a program will not be able to handle an exception, what should be coded into the method?

Select one:

a. The throws clause should list the name of the method to which the exception should be passed.

b. The method declaration should be enclosed in a try/catch block.

c. The method should include a try/catch block for all possible exceptions.

d. The throws clause should list the names of all exceptions that the method will not handle.

20.

Consider the following code snippet:

throw new IllegalArgumentException("This operation is not allowed!"); 

Which of the following statements about this code is correct?

Select one:

a. This code constructs an object of type IllegalArgumentException and throws the object.

b. This code throws an existing IllegalArgumentException object.

c. This code constructs an object of type IllegalArgumentException and reserves it for future use.

d. This code will not compile.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!