Skip to main content

1Z0-809 Real Exam Questions

Java SE 8 Programmer II

207 questions available · Page 1 of 21

Updated Exam DumpsVerified AnswersPass Guarantee

Get Complete Exam Dumps
Question 1 Multiple choice

Which two are elements of a singleton class? (Choose two.)

  1. A

    a transient reference to point to the single instance

  2. B

    a public method to instantiate the single instance

  3. C

    a public static method to return a copy of the singleton reference

  4. D

    a private constructor to the class

  5. E

    a public reference to point to the single instance

Show answer and explanation

Correct answers: B, D

Question 2 Single choice

Given the code fragment:

What is the result?

  1. A

    0 : 0 : pen

  2. B

    0 : 1 : pen

  3. C

    0 : pen

  4. D

    0 : 1 : 2 : 3 : 4 :

  5. E

    A compilation error occurs.

Show answer and explanation

Correct answer: E

Question 3 Single choice

Given the code fragment:

List<String> colors = Arrays.asList("red", "green", "yellow");
Predicate<String> test = n - > {
System.out.println("Searching...");
return n.contains("red");
};
colors.stream()
.filter(c -> c.length() >= 3)
.allMatch(test);

What is the result?

  1. A

    Searching...

  2. B

    Searching...
    Searching...

  3. C

    Searching...
    Searching...
    Searching...

  4. D

    A compilation error occurs.

Show answer and explanation

Correct answer: C

Question 4 Single choice

Given the code fragment:

List<Integer> codes = Arrays.asList (10, 20);
UnaryOperator<Double> uo = s -> s +10.0;
codes.replaceAll(uo);
codes.forEach(c -> System.out.println(c));

What is the result?

  1. A

    20.0
    30.0

  2. B

    10

  3. C

    A compilation error occurs.

  4. D

    A NumberFormatException is thrown at run time.

Show answer and explanation

Correct answer: C

Question 5 Multiple choice

Which two statements are true about synchronization and locks? (Choose two.)

  1. A

    A thread automatically acquires the intrinsic lock on a synchronized statement when executed.

  2. B

    The intrinsic lock will be retained by a thread if return from a synchronized method is caused by an uncaught exception.

  3. C

    A thread exclusively owns the intrinsic lock of an object between the time it acquires the lock and the
    time it releases it.

  4. D

    A thread automatically acquires the intrinsic lock on a synchronized method's object when entering that method.

  5. E

    Threads cannot acquire intrinsic locks on classes.

Show answer and explanation

Correct answers: A, B

Explanation

References:
https://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html

Question 6 Single choice

Given that course.txt is accessible and contains:

Course : : Java

and given the code fragment:

public static void main (String[ ] args) {
int i;
char c;
try (FileInputStream fis = new FileInputStream ("course.txt");
InputStreamReader isr = new InputStreamReader(fis);) {
while (isr.ready()) { //line n1
isr.skip(2);
i = isr.read ();
c = (char) i;
System.out.print(c);
}
}
catch (Exception e) {
e.printStackTrace();
}
}

What is the result?

  1. A

    ur :: va

  2. B

    ueJa

  3. C

    The program prints nothing.

  4. D

    A compilation error occurs at line n1.

Show answer and explanation

Correct answer: B

Question 7 Single choice

Given:

class Vehicle {
int vno;
String name;

public Vehicle (int vno, String name) {
this.vno = vno,;
this.name = name;
}
public String toString () {
return vno + ":" + name;
}
}

and this code fragment:

Set<Vehicle> vehicles = new TreeSet <> ();
vehicles.add(new Vehicle (10123, "Ford"));
vehicles.add(new Vehicle (10124, "BMW"));
System.out.println(vehicles);

What is the result?

  1. A

    10123 Ford
    10124 BMW

  2. B

    10124 BMW
    10123 Ford

  3. C

    A compilation error occurs.

  4. D

    A ClassCastException is thrown at run time.

Show answer and explanation

Correct answer: D

Question 8 Single choice

Given the code fragment:

UnaryOperator<Integer> uo1 = s -> s*2; line n1
List<Double> loanValues = Arrays.asList(1000.0, 2000.0);
loanValues.stream()
.filter(lv -> lv >= 1500)
.map(lv -> uo1.apply(lv))
.forEach(s -> System.out.print(s + " "));

What is the result?

  1. A

    4000.0

  2. B

    4000

  3. C

    A compilation error occurs at line n1.

  4. D

    A compilation error occurs at line n2.

Show answer and explanation

Correct answer: D

Question 9 Single choice

Given the definition of the Vehicle class:

class Vehicle {
String name;
void setName (String name) {
this.name = name;
}
String getName() {
return name;
}
}

Which action encapsulates the Vehicle class?

  1. A

    Make the Vehicle class public.

  2. B

    Make the name variable public.

  3. C

    Make the setName method public.

  4. D

    Make the name variable private.

  5. E

    Make the setName method private.

  6. F

    Make the getName method private.

Show answer and explanation

Correct answer: D

Question 10 Single choice

Given the code fragment:

Stream<List<String>> iStr= Stream.of (
Arrays.asList ("1", "John"),
Arrays.asList ("2", null)0;
Stream<<String> nInSt = iStr.flatMapToInt ((x) -> x.stream ());
nInSt.forEach (System.out :: print);

What is the result?

  1. A

    1John2null

  2. B

    12

  3. C

    A NullPointerException is thrown at run time.

  4. D

    A compilation error occurs.

Show answer and explanation

Correct answer: D