1Z0-809 Premium Bundle

1Z0-809 Premium Bundle

Java SE 8 Programmer II Certification Exam

4.5 
(8160 ratings)
0 QuestionsPractice Tests
0 PDFPrint version
November 5, 2024Last update

Oracle 1Z0-809 Free Practice Questions

Q1. Which statement is true about the single abstract method of the java.util.function.Function interface? 

A. It accepts one argument and returns void. 

B. It accepts one argument and returns boolean. 

C. It accepts one argument and always produces a result of the same type as the argument. 

D. It accepts an argument and produces a result of any data type. 

Answer:

Reference: http://winterbe.com/posts/2014/03/16/java-8-tutorial/ (functions) 

Q2. Given: 

public class SampleClass { 

public static void main(String[] args) { 

AnotherSampleClass asc = new AnotherSampleClass(); SampleClass sc = new 

SampleClass(); 

sc = asc; 

System.out.println("sc: " + sc.getClass()); 

System.out.println("asc: " + asc.getClass()); 

}} 

class AnotherSampleClass extends SampleClass { 

What is the result? 

A. sc: class Object asc: class AnotherSampleClass 

B. sc: class SampleClass asc: class AnotherSampleClass 

C. sc: class AnotherSampleClass asc: class SampleClass 

D. sc: class AnotherSampleClass asc: class AnotherSampleClass 

Answer:

Q3. Given: What is the result? 

A. Initialized Started 

B. Initialized Started Initialized 

C. Compilation fails 

D. An exception is thrown at runtime 

Answer:

Q4. Given: 

IntStream stream = IntStream.of (1,2,3); IntFunction<Integer> inFu= x -> y -> x*y;//line n1 IntStream newStream = stream.map(inFu.apply(10));//line n2 

newStream.forEach(System.output::print); 

Which modification enables the code fragment to compile? 

A. Replace line n1 with: 

IntFunction<UnaryOperator> inFu = x -> y -> x*y; 

B. Replace line n1 with: 

IntFunction<IntUnaryOperator> inFu = x -> y -> x*y; 

C. Replace line n1 with: 

BiFunction<IntUnaryOperator> inFu = x -> y -> x*y; 

D. Replace line n2 with: 

IntStream newStream = stream.map(inFu.applyAsInt (10)); 

Answer:

Q5. Given: 

1. 

abstract class Shape { 

2. 

Shape ( ) { System.out.println (“Shape”); } 

3. 

protected void area ( ) { System.out.println (“Shape”); } 

4. 

5. 

6. 

class Square extends Shape { 

7. 

int side; 

8. 

Square int side { 9./* insert code here */ 

10. 

this.side = side; 

11. 

12. 

public void area ( ) { System.out.println (“Square”); } 

13. 

14. 

class Rectangle extends Square { 

15. 

int len, br; 

16. 

Rectangle (int x, int y) { 

17. 

/* insert code here */ 

18. 

len = x, br = y; 

19. 

20. 

void area ( ) { System.out.println (“Rectangle”); } 

21. 

Which two modifications enable the code to compile? 

A. At line 1, remove abstract 

B. At line 9, insert super ( ); 

C. At line 12, remove public 

D. At line 17, insert super (x); 

E. At line 17, insert super (); super.side = x; 

F. At line 20, use public void area ( ) { 

Answer: C,D 

Q6. Given: 

A. X XX 

B. X Y X 

C. Y Y X 

D. Y YY 

Answer:

Q7. Given: What is the result? 

A. The program prints nothing 

B. d 

C. A StringIndexOutOfBoundsException is thrown at runtime. 

D. AnArrayIndexOutOfBoundsException is thrown at runtime. 

E. A NullPointerException is thrown at runtime. 

Answer:

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

Q9. Given the class definitions: 

And the code fragment of the main() method, 

What is the result? 

A. Java Java Java 

B. Java Jeve va 

C. Java Jeve ve 

D. Compilation fails 

Answer:

Q10. Which action can be used to load a database driver by using JDBC3.0? 

A. Add the driver class to the META-INF/services folder of the JAR file. 

B. Include the JDBC driver class in a jdbc.properties file. 

C. Use the java.lang.Class.forName method to load the driver class. 

D. Use the DriverManager.getDriver method to load the driver class. 

Answer:

Q11. Given the code fragment: 

List<Integer> list1 = Arrays.asList(10, 20); 

List<Integer> list2 = Arrays.asList(15, 30); 

//line n1 

Which code fragment, when inserted at line n1, prints 10 20 15 30? 

A. Stream.of(list1, list2) 

.flatMap(list -> list.stream()) 

.forEach(s -> System.out.print(s + “ “)); 

B. Stream.of(list1, list2) 

.flatMap(list -> list.intStream()) 

.forEach(s -> System.out.print(s + “ “)); 

C. list1.stream() 

.flatMap(list2.stream().flatMap(e1 -> e1.stream()) 

.forEach(s -> System.out.println(s + “ “)); 

D. Stream.of(list1, list2) 

.flatMapToInt(list -> list.stream()) 

.forEach(s -> System.out.print(s + “ “)); 

Answer:

Q12. public class ForTest { 

public static void main(String[] args) { 

int[] arrar = {1,2,3}; 

for ( foo ) { 

Which three are valid replacements for foo so that the program will compiled and run? 

A. int i: array 

B. int i = 0; i < 1; i++ 

C. ;; 

D. ; i < 1; i++ 

E. ; i < 1; 

Answer: A,B,C 

Q13. Given the code fragment: 

Which code fragment prints blue, cyan, ? A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer:

Q14. Given the code fragments: 

class MyThread implements Runnable { 

private static AtomicInteger count = new AtomicInteger (0); 

public void run () { 

int x = count.incrementAndGet(); 

System.out.print (x+” “); 

and 

Thread thread1 = new Thread(new MyThread()); 

Thread thread2 = new Thread(new MyThread()); 

Thread thread3 = new Thread(new MyThread()); 

Thread [] ta = {thread1, thread2, thread3}; 

for (int x= 0; x < 3; x++) { 

ta[x].start(); 

Which statement is true? 

A. The program prints 1 2 3 and the order is unpredictable. 

B. The program prints 1 2 3. 

C. The program prints 1 1 1. 

D. A compilation error occurs. 

Answer:

Q15. Given the code fragment: 

public class Foo { 

public static void main (String [ ] args) { 

Map<Integer, String> unsortMap = new HashMap< > ( ); 

unsortMap.put (10, “z”); 

unsortMap.put (5, “b”); 

unsortMap.put (1, “d”); 

unsortMap.put (7, “e”); 

unsortMap.put (50, “j”); 

Map<Integer, String> treeMap = new TreeMap <Integer, String> (new 

Comparator<Integer> ( ) { 

@Override public int compare (Integer o1, Integer o2) {return o2.compareTo 

(o1); } } ); 

treeMap.putAll (unsortMap); 

for (Map.Entry<Integer, String> entry : treeMap.entrySet () ) { 

System.out.print (entry.getValue () + “ “); 

What is the result? 

A. A compilation error occurs. 

B. d b e z j 

C. j z e b d 

D. z b d e j 

Answer:

START 1Z0-809 EXAM