Skip to content

1z0-809 Java SE 8 Programmer II (OCP) Practice Questions

Prepare for 1z0-809 with more than an answer.

366 questions in the full set20 sample questionsUpdated Jan 23, 2026
Level
Professional
Valid for
Certification does not expire, but Oracle recommends staying current with newer Java versions
Domains covered on the exam 12
  1. Java Class Design
  2. Advanced Java Class Design
  3. Generics and Collections
  4. Lambda Built-in Functional Interfaces
  5. Java Stream API
  6. Exceptions and Assertions
  7. Use Java SE 8 Date/Time API
  8. Java I/O Fundamentals
  9. Java File I/O (NIO.2)
  10. Java Concurrency
  11. Building Database Applications with JDBC
  12. Localization
  1. 1

    Given the code fragments:

    1. void doStuff() throws ArithmeticException, NumberFormatException, Exception {

    2. if (Math.random() )-1 throw new Exception (“Try again');

    3. }

    and

    1. try {

    2. doStuff ( ):

    3. } catch (ArithmeticException | NumberFormatException | Exception e) {

    4. System.out.println (e.getMessage()); }

    5. catch (Exception e) {

    6. System.out.println (e.getMessage()); }

    }

    Which modification enables the code to print Try again?

    Show answer details

    Correct answer: C

    C

  2. 2

    Given the definition of the Country class:

    public class country {

    public enum Continent {ASIA, EUROPE}

    String name;

    Continent region;

    public Country (String na, Continent reg) {

    name = na, region = reg;

    }

    public String getName () {return name;}

    public Continent getRegion () {return region;}

    }

    and the code fragment:

    List(Country) couList = Arrays.asList (

    new Country (“Japan', Country.

    Continent.

    ASIA),

    new Country (“Italy', Country.

    Continent.

    EUROPE),

    new Country (“Germany', Country.

    Continent.

    EUROPE));

    Map(Country.

    Continent, List(String)) regionNames = couList.stream ()

    .collect(Collectors.groupingBy (Country ::getRegion,

    Collectors.mapping(Country::getName, Collectors.toList()))));

    System.out.println(regionNames);

    What is the output?

    Show answer details

    Correct answer: B

    B

  3. 3

    Given the code fragment:

    Map(Integer, String) books = new TreeMap()();

    books.put (1007, “A');

    books.put (1002, “C');

    books.put (1001, “B');

    books.put (1003, “B');

    System.out.println (books);

    What is the result?

    Show answer details

    Correct answer: B

    Reference:

    TreeMap inherits SortedMap and automatically sorts the element's key

  4. 4

    Given:

    class Book {

    int id;

    String name;

    public Book (int id, String name) {

    this.id = id;

    this.name = name;

    }

    public boolean equals (Object obj) { //line n1

    boolean output = false;

    Book b = (Book) obj;

    if (this.name.equals(b name))}

    output = true;

    }

    return output;

    }

    }

    and the code fragment:

    Book b1 = new Book (101, “Java Programing');

    Book b2 = new Book (102, “Java Programing');

    System.out.println (b1.equals(b2)); //line n2

    Which statement is true?

    Show answer details

    Correct answer: A

    A

  5. 5

    Given the content of /resourses/Message.properties:

    welcome1='Good day!'

    and given the code fragment:

    Properties prop = new Properties ();

    FileInputStream fis = new FileInputStream (“/resources/Message.properties');

    prop.load(fis);

    System.out.println(prop.getProperty(“welcome1'));

    System.out.println(prop.getProperty(“welcome2', “Test'));//line n1

    System.out.println(prop.getProperty(“welcome3'));

    What is the result?

    Show answer details

    Correct answer: C

    C

  6. 6

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

    Show answer details

    Correct answer: C

    C

  7. 7

    A systems administrator needs to write a script to find all symbolic links within the /usr/bin directory tree. Which NIO.2 code fragment correctly achieves this?

    flowchart TD Start([Start]) --> Walk{Files.walk("/usr/bin")} Walk --> Filter{Filter for Symbolic Links} Filter --> Print[Print Path] Print --> End([End])
    Show answer details

    Correct answer: C

    Files.walk(path) returns a Stream that recursively walks the directory tree. The requirement is to check each entry to see if it's a symbolic link. The Files::isSymbolicLink method reference is a perfect Predicate for this filtering task. Files.list only lists the immediate contents of a directory, not the whole tree.

  8. 8

    Given the definition of the Vehicle class:

    Class Vehicle {

    int distance;

    Vehicle (int x) {

    this distance = x;

    }

    public void increSpeed(int time) {

    int timeTravel = time; //line n1

    //line n3

    class Car {

    int value = 0;

    public void speed () {

    value = distance /timeTravel;//line n2

    System.out.println (“Velocity with new speed'+value+'kmph');

    }

    }

    speed();//line n3

    }

    }

    and this code fragment:

    Vehicle v = new Vehicle (100);

    v.increSpeed(60);

    What is the result?

    Show answer details

    Correct answer: A

    A

  9. 9

    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.out::print);

    Which modification enables the code fragment to compile?

    Show answer details

    Correct answer: B

    B

  10. 10

    Given the code fragment:

    List(Integer) values = Arrays.asList (1, 2, 3);

    values.stream ()

    .map(n -) n*2)//line n1

    .peek(System.out::print)//line n2

    .count();

    What is the result?

    Show answer details

    Correct answer: A

    A

Create an account to continue.