Premium

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



Question : You have been given following code.

public class Two {

public static void main(String[] args) {
try {
doStuff();
System.out.print("1");
} catch (Exception e) {
System.out.print("2");
}
}

public static void doStuff() {
if (Math.random() > 0.5)
throw new RuntimeException();
doMoreStuff();
System.out.print("3 ");
}

public static void doMoreStuff() {
System.out.print("4");
}
}


Which two are possible outputs?

A. 2
B. 4 3 1
C. 1
D. 1 2

  : You have been given following code.
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D
5. C,D



Correct Answer : Get Lastest Questions and Answer :
Explanation: A: Output is 2 if Math.random() is greater than 0.5. B: If Math.random() returns a value less
equal to 0.5, the code won't throw an exception, it will continue with the doMore() method
which will println "4" after which the program will continue with the doStuff() method and
will println "3", after that we will be back in main() and the program will print "1".





Question : You have been given below code

public class Two {

public static void main(String[] args) {
int day = 1;
switch (day) {
case "7": System.out.print("Uranus");
case "6": System.out.print("Saturn");
case "1": System.out.print("Mercury");
case "2": System.out.print("Venus");
case "3": System.out.print("Earth");
case "4": System.out.print("Mars");
case "5": System.out.print("Jupiter");
}
}
}

Which two modifications, made independently, enable the code to compile and run?
A. Adding a break statement after each print statement
B. Adding a default section within the switch code-block
C. Changing the string literals in each case label to integer
D. Changing the type of the variable day to String
E. Arranging the case labels in ascending order

  : You have been given below code
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,E
5. A,C


Correct Answer : Get Lastest Questions and Answer :
Explanation: Correct code syntex as below

public static void main(String[] args) {
int day = 1;
switch (day) {
case 7: System.out.print("Uranus");
break;
case 6: System.out.print("Saturn");
break;
case 1: System.out.print("Mercury");
break;
case 2: System.out.print("Venus");
break;
case 3: System.out.print("Earth");
break;
case 4: System.out.print("Mars");
break;
case 5: System.out.print("Jupiter");
break;
}





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


  : Which three are advantages of the Java exception mechanism?
1. A,B,C
2. B,C,D
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,C,E
5. A,D,E



Correct Answer : Get Lastest Questions and Answer :
Explanation:





Related Questions


Question : Given the code fragment:

Which modification enables the code fragment to print TrueDone?

  : Given the code fragment:
1. Replace line 5 With String result = "true";
Replace line 7 with case "true":
2. Replace line 5 with int opt = l;
Replace line 7 with case 1 :

3. At line 9, remove the break statement.
4. Remove the default section.




Question : Given the code fragment:
Which modification enables the code to print 54321?
 : Given the code fragment:
1. Replace line 6 with System, out. print (x--) ;
2. At line 1, insert x --;
3. Replace line 6 with --x; and, at line 7, insert system, out. print (x);
4. Replace line 12 With return (x > 0) ? false: true;





Question : Given the code fragment:
What is the result?
  :  Given the code fragment:
1. Reading Card
Card
2. Compilation fails only at line n1.
3. Compilation fails only at line n2.
4. Compilation fails only at line n3.
5. Compilation fails at both line n2 and line n3.



Question : Given the code fragment:

String shirts[][] = new String[2][2];
shirts[0][0]="red";
shirts[0][1]="blue";
shirts[1][0]="small";
shirts[1][1]="medium";

Which code fragment prints red: blue: small: medium?


 :  Given the code fragment:
1. A

2. B
3. C

4. D



Question :


A. this.amount = 0;
B. amount = 0;
C. acct (0) ;
D. acct.amount = 0;
E. acct. getAmount () = 0;
F. acct.changeAmount(0);
G. acct.changeAmount(-acct.amount);
H. acct.changeAmount(-acct.getAmount());


 :
1. A,B,C
2. A,C,D
3. D,G,H
4. E,F,G
5. A,E,F




Question : Given the code fragment from three files:
Which code fragment, when inserted at line 2 (in third file), enables the code to compile?


package sales;
public class SalesMan { }

package sales.products;
public class Product { }

package market;
//insert code here
public class USMarket {
SalesMan sm;
Product p;
}
 :  Given the code fragment from three files:
1. import sales.*;

2. import java.sales.products.*;
3. import sales;
import sales.products;
4. import sales.*;
import sales.products.*;