1z0-809 Sample Questions

1z0-809 Sample Questions & Answers

Spans lambda expressions and built-in functional interfaces tied with Stream API operations, generics and collections, advanced class design using abstract and inner classes, exceptions and assertions, the Date and Time API, file I/O, concurrency, JDBC and localization.

Launch the full 1z0-809 simulator →

Showing 10 of 20 free samples.

  1. Question 1

    Given:

    public class Counter {

    public static void main (String[ ] args) {

    int a = 10;

    int b = -1;

    assert (b )=1) : “Invalid Denominator';

    int = a / b;

    System.out.println (c);

    }

    }

    What is the result of running the code with the -ea option?

    Show answer & explanation

    Correct answer: C

    C

  2. Question 2

    Given:

    class Bird {

    public void fly () { System.out.print(“Can fly'); }

    }

    class Penguin extends Bird {

    public void fly () { System.out.print(“Cannot fly'); }

    }

    and the code fragment:

    class Birdie {

    public static void main (String [ ] args) {

    fly( ( ) -) new Bird ( ));

    fly (Penguin : : new);

    }

    /* line n1 */

    }

    Which code fragment, when inserted at line n1, enables the Birdie class to compile?

    Show answer & explanation

    Correct answer: C

    C

  3. Question 3Select 2

    Given:

    1. abstract class Shape {

    2. Shape ( ) { System.out.println (“Shape'); }

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

    4. }

    5. class Square extends Shape {

    6. int side;

    7. Square int side {

    8. /* insert code here */

    9. this.side = side;

    10. }

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

    12. }

    13. class Rectangle extends Square {

    14. int len, br;

    15. Rectangle (int x, int y) {

    16. /* insert code here */

    17. len = x, br = y;

    18. }

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

    20. }

    Which two modifications enable the code to compile? (Choose two.)

    Show answer & explanation

    Correct answers: D, F

    D,F

    D,F

  4. Question 4

    Given:

    class Sum extends RecursiveAction { //line n1 static final int THRESHOLD_SIZE = 3;

    int stIndex, lstIndex;

    int [ ] data;

    public Sum (int [ ]data, int start, int end) {

    this.data = data;

    this stIndex = start;

    this. lstIndex = end;

    }

    protected void compute ( ) {

    int sum = 0;

    if (IstIndex - stIndex (= THRESHOLD_SIZE) {

    for (int i = stIndex; i ( lstIndex; i++) {

    sum += data [i];

    }

    System.out.println(sum);

    } else {

    new Sum (data, stIndex + THRESHOLD_SIZE, lstIndex).fork( );

    new Sum (data, stIndex,

    Math.min (lstIndex, stIndex + THRESHOLD_SIZE)

    ).compute ();

    }

    }

    }

    and the code fragment:

    ForkJoinPool fjPool = new ForkJoinPool ( );

    int data [ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

    fjPool.invoke (new Sum (data, 0, data.length));

    and given that the sum of all integers from 1 to 10 is 55.
    Which statement is true?

    Show answer & explanation

    Correct answer: A

    A

  5. Question 5

    Given the content of Operator.java, EngineOperator.java, and Engine.java files:

    What is the result?

    1z0-809 sample question 5
    Show answer & explanation

    Correct answer: A

    A

  6. Question 6

    Given the code fragment:

    Stream(List(String)) iStr= Stream.of (

    Arrays.asList (“1', “John'),

    Arrays.asList (“2', null));

    Stream((String) nInSt = iStr.flatMapToInt ((x) -) x.stream ());

    nInSt.forEach (System.out :: print);

    What is the result?

    Show answer & explanation

    Correct answer: D

    D

  7. Question 7

    Given the code fragment:

    Path file = Paths.get (“courses.txt');

    // line n1

    Assume the courses.txt is accessible.

    Which code fragment can be inserted at line n1 to enable the code to print the content of the courses.txt file?

    Show answer & explanation

    Correct answer: D

    D

  8. Question 8

    Given the code fragment:

    public void recDelete (String dirName) throws IOException {

    File [ ] listOfFiles = new File (dirName) .listFiles();

    if (listOfFiles ! = nulllistOfFiles.length )0) {

    for (File aFile : listOfFiles) {

    if (aFile.isDirectory ()) {

    recDelete (aFile.getAbsolutePath ());

    } else {

    if (aFile.getName ().endsWith (“.class'))

    Oracle 1z0-809 Exam aFile.delete ();

    }

    }

    }

    }

    Assume that Projects contains subdirectories that contain .class files and is passed as an argument to the recDelete () method when it is invoked.

    What is the result?

    Show answer & explanation

    Correct answer: A

    A

  9. Question 9

    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 & explanation

    Correct answer: C

    C

  10. Question 10

    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 & explanation

    Correct answer: B

    B

Ready for the real thing?

The full 1z0-809 simulator has every exam-style question, timed mode, and instant scoring.