1z0-808 Premium Bundle

1z0-808 Premium Bundle

Java SE 8 Programmer I Certification Exam

4.5 
(13410 ratings)
0 QuestionsPractice Tests
0 PDFPrint version
November 23, 2024Last update

Oracle 1z0-808 Free Practice Questions

Q1. Given the code fragment: 

int b = 3; 

if ( !(b > 3)) { 

System.out.println("square "); 

}{ 

System.out.println("circle "); 

System.out.println("..."); 

What is the result? 

A. square... 

B. circle... 

C. squarecircle... 

D. Compilation fails. 

Answer:

Q2. Given the code fragment: 

What is the result if the integer aVar is 9? 

A. 10 Hello world! 

B. 10 Hello universe! 

C. 9 Hello world! 

D. Compilation fails. 

Answer:

Q3. Given the following code for the classes MyException and Test: 

What is the result? 

A. A 

B. B 

C. Either A or B 

D. A B 

E. A compile time error occurs at line n1 

Answer:

Q4. Given the code fragments: 

What is the result? 

A. Super Sub Sub 

B. Contract Contract Super 

C. Compilation fails at line n1 

D. Compilation fails at line n2 

Answer:

Q5. Given the following two classes: 

How should you write methods in the ElectricAccount class at line n1 so that the member variable bill is always equal to the value of the member variable kwh multiplied by the member variable rate? 

Any amount of electricity used by a customer (represented by an instance of the customer class) must contribute to the customer's bill (represented by the member variable bill) through the method useElectricity method. An instance of the customer class should never be able to tamper with or decrease the value of the member variable bill. 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer:

Q6. Given the code fragment: 

What is the result? 

A. Sum is 600 

B. Compilation fails at line n1. 

C. Compilation fails at line n2. 

D. A ClassCastException is thrown at line n1. 

E. A ClassCastException is thrown at line n2. 

Answer:

Q7. Given: 

public class ColorTest { 

public static void main(String[] args) { 

String[] colors = {"red", "blue","green","yellow","maroon","cyan"}; 

int count = 0; 

for (String c : colors) { 

if (count >= 4) { 

break; 

else { 

continue; 

if (c.length() >= 4) { 

colors[count] = c.substring(0,3); 

count++; 

System.out.println(colors[count]); 

What is the result? 

A. Yellow 

B. Maroon 

C. Compilation fails 

D. A StringIndexOutOfBoundsException is thrown at runtime. 

Answer:

Explanation: The line, if (c.length() >= 4) {, is never reached. This causes a compilation error. 

Note: The continue statement skips the current iteration of a for, while , or do-while loop. An unlabeled.break.statement terminates the innermost.switch,.for,.while, or.do-while.statement, but a labeled.break.terminates an outer statement. 

Q8. 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? 

A. AssertionError, ArrayIndexOutOfBoundsException, ArithmeticException 

B. AssertionError, IOError, IOException 

C. ArithmeticException, FileNotFoundException, NumberFormatException 

D. FileNotFoundException, IOException, SQLException 

E. ArrayIndexOutOfBoundException, IllegalArgumentException, FileNotFoundException 

Answer:

Explanation: Not B: IOError and IOException are both checked errors. 

Not C, not D, not E: FileNotFoundException is a checked error. 

Note: 

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) 

Note: 

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) 

Q9. Given: 

What is the result? 

A. box 

B. nbo 

C. bo 

D. nb 

E. An exception is thrown at runtime 

Answer:

Q10. Which two statements correctly describe checked exception? 

A. These are exceptional conditions that a well-written application should anticipate and recover from. 

B. These are exceptional conditions that are external to the application, and that the application usually cannot anticipate or recover from. 

C. These are exceptional conditions that are internal to the application, and that the application usually cannot anticipate or recover from. 

D. Every class that is a subclass of RuntimeException and Error is categorized as checked exception. 

E. Every class that is a subclass of Exception, excluding RuntimeException and its subclasses, is categorized as checked exception. 

Answer: B,D 

Explanation: Checked exceptions: 

* (B) 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 It's somewhat confusing, but note as well that RuntimeException (unchecked) is itself a subclass of Exception (checked). 

* 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) 

Reference: Checked versus unchecked exceptions 

Q11. Given: 

What is the result? 

A. 0 Done 

B. First Exception Done 

C. Second Exception 

D. Done Third Exception 

E. Third Exception 

Answer:

Q12. Given the following array: 

Which two code fragments, independently, print each element in this array? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

E. Option E 

F. Option F 

Answer: B,E 

Explanation: All the remaining options have syntax errors 

Q13. Given the code fragment: 

Which code fragment, when inserted at line 9, enables the code to print true? 

A. String str2 = str1; 

B. String str2 = new String (str1); 

C. String str2 = sb1. toString (); 

D. String str2 = "Duke"; 

Answer:

Q14. Consider 

Integer number = Integer.valueOff 808.1"); 

Which is true about the above statement? 

A. The value of the variable number will be 808.1 

B. The value of the variable number will be 808 

C. The value of the variable number will be 0. 

D. A NumberFormatException will be throw. 

E. It will not compile. 

Answer:

Explanation: 

The Integer class value of 0 returns an Integer from given string. But we need to pass string which has correct format for integer otherwise it will throw a NumberFormatException. In this case we have passed string which is not an integer value (since what we passed is fractional number), so option D is correct. 

Q15. Given: 

What is the result? 

A. 11, 21, 31, 11, 21, 31 

B. 11, 21, 31, 12, 22, 32 

C. 12, 22, 32, 12, 22, 32 

D. 10, 20, 30, 10, 20, 30 

Answer:

START 1z0-808 EXAM