Premium

Oracle Java Programming Certification Questions and Answers (Dumps and Practice Questions)



Question : Which usage represents a valid way of compiling java source file with the name "Main"?
 : Which usage represents a valid way of compiling java source file with the name
1. javac Main.java
2. java Main.class
3. Access Mostly Uused Products by 50000+ Subscribers
4. javac Main

5. java Main





Correct Answer : Get Lastest Questions and Answer :
Explanation: The compiler is invoked by the javac command. When compiling a Java class, you must
include the file name, which houses the main classes including the Java extension. So to run
Main.java file we have to use command in option A. TO execute Java program we can use
Java command but can't use it for compiling.








Question : Given the classes:
- AssertionError
- ArithmeticException
- ArrayIndexOutofBoundsException
- FileNotFoundException
- IllegalArgumentException
- IOError
- IOException
- NumberFormatException
- SQLException

Which option lists only those classes that belong to the unchecked exception category?




  : Given the classes:
1. AssertionError, ArrayIndexOutOfBoundsException, ArithmeticException
2. AssertionError, IOError, IOException
3. Access Mostly Uused Products by 50000+ Subscribers
4. FileNotFoundException, IOException, SQLException
5. ArrayIndexOutOfBoundException, IllegalArgumentException, FileNotFoundException




Correct Answer : Get Lastest Questions and Answer :
Explanation:
Not B: IOError and IOException are both checked errors. Not C, not D, not E
FileNotFoundException is a checked error.

Checked exceptions:
- represent invalid conditions in areas outside the immediate control of the program (invalid user input, database problems, network outages, absent files)
- are subclasses of Exception
- a method is obliged to establish a policy for all checked exceptions thrown by its implementation (either pass the checked exception further up the stack, or handle it somehow)

Unchecked exceptions:
- represent defects in the program (bugs) - often invalid arguments passed to a non-private method. To quote from The Java Programming Language, by Gosling, Arnold, and Holmes:
"Unchecked runtime exceptions represent conditions that, generally speaking, reflect errors in your program's logic and cannot be reasonably recovered from at run time."
- are subclasses of RuntimeException, and are usually implemented using IllegalArgumentException, NullPointerException, or IllegalStateException
- method is not obliged to establish a policy for the unchecked exceptions thrown by its implementation (and they almost always do not do so)





Question : You have been given below code


Int[][] array = {{0}, {0, 1}, {0, 2, 4}, {0, 3, 6, 9}, {0, 4, 8, 12, 16}};
System.out.println(array [4][1]);
System.out.printIn (array) [1][4]);


What would be the result?

  : You have been given below code
1. 4 Null
2. Null 4
3. Access Mostly Uused Products by 50000+ Subscribers
4. 4 An ArrayIndexOutOfBoundException is thrown at run time



Correct Answer : Get Lastest Questions and Answer :
Explanation: The first println statement, System.out.println(array [4][1]);, works fine. It selects the
element/array with index 4, {0, 4, 8, 12, 16}, and from this array it selects the element with
index 1, 4. Output: 4 The second println statement, System.out.println(array) [1][4]);, fails. It
selects the array/element with index 1, {0, 1}, and from this array it try to select the element
with index 4. This causes an exception.
Output: 4 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4



Related Questions


Question : Given the code fragment: What is the result?

public static void main(String args[]){
int ii=0;
int jj=7;
for(ii=0; ii System.out.print(ii + " ");
}

  : Given the code fragment: What is the result?
1. 2 4
2. 0 2 4 6
3. 0 2 4
4. Compilation Fails




Question : Given: What is the result?
  : Given: What is the result?
1. ns = 50 s =125
ns = 125 s = 125
ns = 100 s = 125
2. ns = 50 s =125
ns = 125 s = 125
ns = 0 s = 125
3. ns = 50 s =50
ns = 125 s = 125
ns = 100 s = 100
4. ns = 50 s =50
ns = 125 s = 125
ns = 0 s = 125





Question : Given the code from the Greeting.Java file:

public class Greeting {
public static void main(String args[]){
System.out.println("Hello " + args[0]);
}
}

Which set of commands prints Hello Duke in the console?

  : Given the code from the Greeting.Java file:
1. javac Greeting
java Greeting Duke
2. javac Greeting.java Duke
java Greeting
3. javac Greeting.java
java Greeting Duke
4. javac Greeting.java
java Greeting.class Duke





Question : Which three are advantages of the Java exception mechanism?
A. Improves the program structure because the error handling code is separated from the normal program function
B. Provides a set of standard exceptions that covers all the possible errors
C. Improves the program structure because the programmer can choose where to handle exceptions
D. Improves the program structure because exceptions must be handled in the method in which they occurred
E. Allows the creation of new exceptions that are tailored to the particular program being created
  : Which three are advantages of the Java exception mechanism?
1. A,B,C
2. B,D,E
3. A,C,D
4. B,C,E


Exp : A program can use exceptions to indicate that an error occurred. To throw an exception, use the throw statement and provide it with an exception object - a descendant of
Throwable - to provide information about the specific error that occurred. A method that throws an uncaught, checked exception must include a throws clause in its declaration.

A program can catch exceptions by using a combination of the try, catch, and finally blocks.

The try block identifies a block of code in which an exception can occur.
The catch block identifies a block of code, known as an exception handler, that can handle a particular type of exception.
The finally block identifies a block of code that is guaranteed to execute, and is the right place to close files, recover resources, and otherwise clean up after the code enclosed
in the try block.
The try statement should contain at least one catch block or a finally block and may have multiple catch blocks.

The class of the exception object indicates the type of exception thrown. The exception object can contain further information about the error, including an error message. With exception chaining, an exception can point to the exception that caused it, which can in turn point to the exception that caused it, and so on.
Advantage 1: Separating Error-Handling Code from "Regular" Code
Advantage 2: Propagating Errors Up the Call Stack
Advantage 3: Grouping and Differentiating Error Types




Question : Given the code fragment: What is the result?


  : Which three are advantages of the Java exception mechanism?
1. A B C Work done
2. A B C D Work done
3. A Work done
4. Compilation fails


Question : Given the code fragment:
Which code fragment, when inserted at line 3, enables the code to print 10:20?

  :  Given the code fragment:
1. int[] array n= new int[2];
2. int[] array;
array = int[2];
3. int array = new int[2];
4. int array [2] ;



Question : Given:

What is the result?
  : Given:
1. 3 4 5 6

2. 3 4 3 6
3. 5 4 5 6

4. 3 6 4 6