1z0-808 Exam - Java SE 8 Programmer I

certleader.com

Q1. Given the code fragment: 

What is the result? 

A. Match 1 

B. Match 2 

C. No Match 

D. A NullPointerException is thrown at runtime. 

Answer:

Explanation: 

it will compare the string contents of the StringBuilder with string object. 

Q2. Given: 

What is the result? 

A. 3 4 5 6 

B. 3 4 3 6 

C. 5 4 5 6 

D. 3 6 4 6 

Answer:

Q3. Given: 

What will be the output? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer:

Q4. Given: 

What is the result? 

A. Null 

B. Compilation fails 

C. An exception is thrown at runtime 

D. 0 

Answer:

Q5. 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:

Q6. Given the code fragment from three files: 

Which code fragment, when inserted at line 2, enables the code to compile? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

E. Option E 

Answer:

Q7. Given: 

public class MyClass { 

public static void main(String[] args) { 

while (int ii = 0; ii < 2) { 

ii++; 

System.out.println("ii = " + ii); 

What is the result? 

A. ii = 1 ii = 2 

B. Compilation fails 

C. The program prints nothing 

D. The program goes into an infinite loop with no output 

E. The program goes to an infinite loop outputting: ii = 1 ii = 1 

Answer:

Explanation: The while statement is incorrect. It has the syntax of a for statement. 

The while statement continually executes a block of statements while a particular condition is true. Its syntax can be expressed as: 

while (expression) { statement(s) } The while statement evaluates expression, which must return a boolean value. If the expression evaluates to true, the while statement executes the statement(s) in the while block. The while statement continues testing the expression and executing its block until the expression evaluates to false. 

Reference: The while and do-while Statements 

Q8. int [] array = {1,2,3,4,5}; 

for (int i: array) { 

if ( i < 2) { 

keyword1 ; 

System.out.println(i); 

if ( i == 3) { 

keyword2 ; 

}} 

What should keyword1 and keyword2 be respectively, in oreder to produce output 2345? 

A. continue, break 

B. break, break 

C. break, continue 

D. continue, continue 

Answer:

Q9. Given the code fragment: 

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

A. int[] array n= new int[2]; 

B. int[] array; array = int[2]; 

C. int array = new int[2]; 

D. int array [2] ; 

Answer:

Q10. Given: 

What is the result? 

A. Initialized Started 

B. Initialized Started Initialized 

C. Compilation fails 

D. An exception is thrown at runtime 

Answer: