Loading provider exams...
1Z0-809: Java SE 8 Programmer II Certification Exam Practice Exam
Exams / Oracle / 1Z0-809: Java SE 8 Programmer II Certification Exam About the Exam Oracle University's 1Z0-809 exam is the Java SE 8 Programmer II Certification Exam and the second exam in the Java SE 8 OCP path. It is aimed at Java developers building on Java SE 8 fundamentals and preparing for Oracle's Professional Java SE 8 Developer credential. Passing it demonstrates advanced Java SE 8 programming proficiency as part of the Oracle certification sequence.
Exam Topics Java Class Design 6–11% Advanced Class Design 9–14% Generics and Collections 8–13% Collections / Streams / Filters 12–17% Lambda Built-in Functional Interfaces 4–8% Java Stream API 10–14% Exception Handling and Assertions 5–10% Java SE 8 Date/Time API 5–10% Java I/O Fundamentals 5–10% Java File I/O (NIO.2) 4–8% Java Concurrency 8–13% Creating Database Applications with JDBC 8–13% How to Use This Practice Exam Browse — Read each question, select your answer, and reveal the explanation.Exam Mode — Simulate real exam conditions with a timed session and score report.Learn Mode — Spaced repetition schedules questions you struggle with for long-term retention.Download the Full Exam PDF Get every question and answer in a clean, printable PDF built for offline study. Purchase once, keep permanent access, and re-download the latest version anytime.
Last updated July 13, 2026 at 8:18 PM
Topic filter All Topics Question sort Question Number
Question Q 1Java Stream API Copy link Report a problem Ask AstroTutor Save question
Which of the following statements about java.util.stream.Stream is true?
A A stream cannot be consumed more than once. B The execution mode of streams can be changed during processing. C Streams are intended to modify the source data. D A parallel stream is always faster than an equivalent sequential stream. E Stream operation accepts lambda expressions as its parameters. Show Answer Answer Explanation The Stream API is designed so that a stream's elements can only be traversed once for the life of the stream. Once a terminal operation has been invoked on a stream, that stream is considered consumed/closed, and any further attempt to invoke an intermediate or terminal operation on it results in an IllegalStateException with a message such as 'stream has already been operated upon or closed'. This behavior is explicitly documented in the java.util.stream package Javadoc under stream operations and pipelines.
Learn more
Question Q 3Java Concurrency Copy link Report a problem Ask AstroTutor Save question
Question Q 4Java Class Design Copy link Report a problem Ask AstroTutor Save question
Question Q 5Java Class Design Copy link Report a problem Ask AstroTutor Save question
Question Q 6Java Concurrency Copy link Report a problem Ask AstroTutor Save question It's free 100% of the questions are free for all users. No strings attached.
Topics covered Java Class Design Advanced Class Design Generics and Collections Collections / Streams / Filters Lambda Built-in Functional Interfaces Java Stream API Exception Handling and Assertions Java SE 8 Date/Time API Java I/O Fundamentals Java File I/O (NIO.2) Java Concurrency Creating Database Applications with JDBC
Given these code fragments:
class MyThread implements Runnable \{
private static AtomicInteger count = new AtomicInteger(0);
public void run() \{
int x = count.incrementAndGet();
System.out.print(x + " ");
\}
\}
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 correct?
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. Show Answer Answer Explanation A static AtomicInteger is shared by every MyThread instance. Its incrementAndGet() operation is atomic, so the three invocations obtain the unique values 1, 2, and 3. Scheduling is nondeterministic, so the print order is unpredictable.
Given the following declarations:
public class Canvas implements Drawable \{
public void draw() \{ \}
\}
public abstract class Board extends Canvas \{ \}
public class Paper extends Canvas \{
protected void draw(int color) \{ \}
\}
public class Frame extends Canvas implements Drawable \{
public void resize() \{ \}
\}
public interface Drawable \{
public abstract void draw();
\}
Which statement is correct?
A Board does not compile. B Paper does not compile. C Frame does not compile. D Drawable does not compile. E All classes compile successfully. Show Answer Answer Explanation All classes compile successfully. Canvas provides the required public draw() implementation. Board, Paper, and Frame inherit that implementation; Paper.draw(int) is a valid overload rather than an invalid reduction of visibility, and Frame may redundantly declare that it implements Drawable.
Given:
What is the outcome?
A Bar Hello Foo Hello B Bar Hello Baz Hello C Baz Hello D A compilation error occurs in the Daze class. Show Answer Answer Explanation The Bar instance stored in b dispatches to Bar.methodB, printing Bar Hello. The super.methodB(s) invocation directly calls the immediate superclass implementation, Baz.methodB, printing Baz Hello.
Given this code fragment:
class CallerThread implements Callable<String> \{
String str;
public CallerThread(String s) \{ this.str = s; \}
public String call() throws Exception \{
return str.concat("Call");
\}
\}
and
public static void main(String[] args) throws InterruptedException, ExecutionException \{
ExecutorService es = Executors.newFixedThreadPool(4); // line n1
Future f1 = es.submit(new CallerThread("Call"));
String str = f1.get().toString();
System.out.println(str);
\}
Which statement is correct?
A The program prints Call Call and terminates. B The program prints Call Call and does not terminate. C A compilation error occurs at line n1. D An ExecutionException is thrown at run time. Show Answer Answer Explanation The Callable returns "CallCall", and Future.get() retrieves that successful result for printing. Because the fixed-thread-pool ExecutorService is never shut down, it is not terminated after the task completes; an orderly shutdown requires calling shutdown() (and, if needed, waiting with awaitTermination). Java ExecutorService documentation
Learn more
Question Q 7Java File I/O (NIO.2) Copy link Report a problem Ask AstroTutor Save question
Question Q 9Collections / Streams / Filters Copy link Report a problem Ask AstroTutor
Question Q 10Java Concurrency Copy link Report a problem Ask AstroTutor
Question Q 11Java Class Design Copy link Report a problem Ask AstroTutor
Question Q 12Lambda Built-in Functional Interfaces Copy link Report a problem Ask AstroTutor
Question Q 13Java Concurrency Copy link Report a problem Ask AstroTutor
Question Q 15Java I/O Fundamentals Copy link Report a problem Ask AstroTutor
Question Q 16Java SE 8 Date/Time API Copy link Report a problem Ask AstroTutor
Question Q 17Lambda Built-in Functional Interfaces Copy link Report a problem Ask AstroTutor
Question Q 18Generics and Collections Copy link Report a problem Ask AstroTutor
Question Q 19Java I/O Fundamentals Copy link Report a problem Ask AstroTutor
Question Q 21Java Stream API Copy link Report a problem Ask AstroTutor
Question Q 22Java Stream API Copy link Report a problem Ask AstroTutor
Question Q 23Exception Handling and Assertions Copy link Report a problem Ask AstroTutor
Question Q 24Java SE 8 Date/Time API Copy link Report a problem Ask AstroTutor
Question Q 25Creating Database Applications with JDBC Copy link Report a problem Ask AstroTutor
Question Q 26Java File I/O (NIO.2) Copy link Report a problem Ask AstroTutor
Question Q 27Java Stream API Copy link Report a problem Ask AstroTutor
Question Q 28Exception Handling and Assertions Copy link Report a problem Ask AstroTutor
Question Q 29Lambda Built-in Functional Interfaces Copy link Report a problem Ask AstroTutor Save question
Save question
Save question
Save question
Save question
Save question
Save question
Save question
Save question
Save question
Save question
Save question
Save question
Save question
Save question
Save question
Save question
Save question
Save question
Given the contents of the employee.txt file:
> Every worker is a master.
Given that employee.txt is accessible, that allemp.txt does NOT exist, and the following code fragment:
What is the result?
A Exception 1 B Exception 2 C The program executes, does NOT affect the system, and produces NO output. D allemp.txt is created and the content of employee.txt is copied to it. Show Answer Answer Explanation StandardOpenOption.APPEND writes to the end of an existing file; it does not create a missing file unless CREATE is also specified. Since allemp.txt does not exist, Files.write throws an IOException, which the inner catch block handles by printing Exception 1.
Learn more Given this 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
(o2); \}
\});
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 Show Answer Answer Explanation The source as shown does not import the java.util types used by Map, HashMap, TreeMap, Comparator, and Map.Entry; those unresolved types cause compilation to fail.
Given these code fragments:
and
What is the outcome?
A The program prints Run"¦ and throws an exception. B A compilation error occurs at line n1. C Run"¦ Call"¦ D A compilation error occurs at line n2. Show Answer Answer Explanation ExecutorService.execute accepts the Runnable instance, while submit(Callable<T>) accepts the Callable<String> instance and returns a Future<String>. The callable returns "Call...", which get() retrieves for println. A single-thread executor processes the runnable before the subsequently submitted callable, producing Run... Call....
Given the following class:
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.id == b.id) \{
output = true;
\}
return output;
\}
\}
And this 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 correct?
A The program prints true. B The program prints false. C A compilation error occurs. To ensure successful compilation, replace line n1 with: boolean equals (Book obj) { D A compilation error occurs. To ensure successful compilation, replace line n2 with: System.out.println (b1.equals((Object) b2)); Show Answer Answer Explanation equals(Object) is a valid method signature. It compares the id fields of the two Book objects, and 101 == 102 evaluates to false; therefore, the printed value is false.
Which statement is accurate about the sole abstract method in 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. Show Answer Answer Explanation Function<T, R> defines R apply(T t): it accepts one argument and returns a result of type R, which can differ from the argument type T.
Which two statements are correct about the Fork/Join Framework?
Choose two A The RecursiveTask subclass is used when a task does not need to return a result. B The Fork/Join framework can help you take advantage of multicore hardware. C The Fork/Join framework implements a work-stealing algorithm. D The Fork/Join solution when run on multicore hardware always performs faster than standard sequential solution. Show Answer Answer Explanation The Fork/Join Framework supports parallel execution that can use multicore hardware, and its worker threads use a work-stealing algorithm to balance queued tasks. A RecursiveTask returns a result, while RecursiveAction is used when no result is needed; parallel overhead also means Fork/Join is not always faster than a sequential solution.
Given this code fragment:
public static void main (String [ ] args) throws IOException \{
BufferedReader br = new BufferedReader (new InputStremReader (System.in));
System.out.print ("Enter GDP: ");
//line 1
\}
Which code fragment, inserted at line 1, allows the code to read the GDP entered by the user?
A int GDP = Integer.parseInt (br.readline()); B int GDP = br.read(); C int GDP = br.nextInt(); D int GDP = Integer.parseInt (br.next()); Show Answer Answer Explanation BufferedReader.read() reads the next input character and returns its value as an int, so its result can be stored in an int variable. BufferedReader does not provide nextInt() or next(), and its line-reading method is named readLine(), not readline().
Given the following code fragment:
Assume that now has the value 6:30 in the morning.
What is the outcome?
A An exception is thrown at run time. B 0 C 60 D 1 Show Answer Answer Explanation office_start.isAfter(now) is true because 7:30 is later than 6:30. LocalTime.until calculates the elapsed amount in the requested unit, and the interval from 6:30 to 7:30 is 60 minutes.
Learn more Given this code fragment:
BiFunction<Integer, Double, Integer> val = (t1, t2) -> t1 + t2; // line n1
System.out.println(val.apply(10, 10.5));
What is the result?
A 20 B 20.5 C A compilation error occurs at line n1. D A compilation error occurs at line n2. Show Answer Answer Explanation Adding an Integer and a Double unboxes both operands and yields a double. The BiFunction declares Integer as its result type, and Java does not implicitly narrow a double result to int and box it into an Integer; therefore, the lambda fails to compile at line n1.
Given the code fragment:
What is the result?
A 4000 : 2000 B 4000 : 1000 C 1000 : 4000 D 1000 : 2000 Show Answer Answer Explanation For ArrayDeque, push adds an element at the head of the deque, while remove and pop remove and return the head element. Thus, 4000 is removed first, followed by 1000.
Given that data.txt and alldata.txt are accessible, and the code fragment:
What is needed at line n1 so the code overwrites alldata.txt with data.txt?
A br.close(); B bw.writeln(); C br.flush(); D bw.flush(); Show Answer Answer Explanation BufferedWriter.flush() sends any characters retained in the writer’s buffer to its underlying FileWriter, making the copied content available in alldata.txt. A FileWriter constructed without the append argument uses overwrite mode; the required remaining operation is flushing the buffered output. Oracle’s BufferedWriter documentation specifies that flush() flushes the stream.
Learn more Given the following code fragment:
What is the outcome?
A A compilation error occurs at line n1. B Checking"¦ C Checking"¦ Checking"¦ D A compilation error occurs at line n2. Show Answer Answer Explanation filter passes only elements whose predicate evaluates to true. The length predicate allows best and luck through, and the equality predicate executes once for each of those two elements. It prints Checking... before returning false, so the output contains two Checking... lines; count() itself is not printed. Oracle Stream API
Learn more Given this 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?
A 246 B The code produces no output. C A compilation error occurs at line n1. D A compilation error occurs at line n2. Show Answer Answer Explanation count() may use the stream’s known size rather than traverse its elements. The Stream API permits eliding intermediate operations when doing so does not affect the terminal result; therefore the peek action is not guaranteed to run, and nothing is printed.
Given these code fragments:
and
What is the outcome?
A Video played.Game played. B A compilation error occurs. C class java.lang.Exception D class java.io.IOException Show Answer Answer Explanation An overriding method may declare only the same checked exceptions as the overridden method or narrower subclasses. Because Exception is broader than IOException, Game.play() cannot override Video.play() with that throws clause, causing a compilation error. Java Language Specification, §11
Learn more Given this code fragment:
ZonedDateTime depart = ZonedDateTime.of(2015, 1, 15, 3, 0, 0, 0, ZoneID.of("UTC-7"));
ZonedDateTime arrive = ZonedDateTime.of(2015, 1, 15, 9, 0, 0, 0, ZoneID.of("UTC-5")); long hrs = ChronoUnit.HOURS.between(depart, arrive); //line n1
System.out.println("Travel time is" + hrs + "hours");
What is the outcome?
A Travel time is 4 hours B Travel time is 6 hours C Travel time is 8 hours D An exception is thrown at line n1. Show Answer Answer Explanation Time-based units for ZonedDateTime operate on the instant timeline. 03:00 at UTC−7 corresponds to 10:00 UTC, while 09:00 at UTC−5 corresponds to 14:00 UTC, producing an elapsed interval of four hours.
Learn more Given the records in the Player table:
and the following code fragment:
try \{
Connection conn = DriverManager.getConnection(URL, username, password);
Statement st= conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
st.execute ("SELECT * FROM Player");
st.setMaxRows(2);
ResultSet rs = st.getResultSet();
rs.absolute(3);
while (rs.next ()) \{
System.out.println(rs.getInt(1) + " " + rs.getString(2));
\}
\} catch (SQLException ex) \{
System.out.print("SQLException is thrown.");
\}
Assume that:
The required database driver is configured in the classpath.
The appropriate database is accessible with URL, username, and password.
The SQL query is valid.
What is the output?
A 2 Jack 3 Sam B The program prints nothing. C 3 Sam D SQLException is thrown. Show Answer Answer Explanation ResultSet.absolute(3) places the cursor on row 3. ResultSet.next() advances it one row; because there is no row after the third row, it returns false, so the loop body does not execute and nothing is printed. The Java ResultSet API specifies these cursor movements.
Learn more Given this code fragment:
Path p1 = Paths.get("/Pics/MyPic.jpeg");
System.out.println(p1.getNameCount() +
":" + p1.getName(1) +
":" + p1.getFileName());
Assume that the Pics directory does not exist. What is the result?
A An exception is thrown at run time. B 2:MyPic.jpeg: MyPic.jpeg C 3:.:MyPic.jpeg D 2:Pics: MyPic.jpeg Show Answer Answer Explanation A Path is a lexical representation and its component-access methods do not access the file system. The root is not a name element, so /Pics/MyPic.jpeg has two name elements. Index 1 and the file name are both MyPic.jpeg; the directory’s nonexistence does not cause an exception. Oracle specifies that getNameCount() returns name elements, getName(0) is nearest the root, and getFileName() returns the farthest name element from the root.
Learn more Given the following Product class:
public class Product \{
int id;
int price;
public Product(int id, int price) \{
this.id = id;
this.price = price;
\}
Public String toString() \{ return id + ":" + price;)
\}
And this code fragment:
List<Product> products = new ArrayList<>(Arrays.asList(
new Product(1, 10), new Product(2, 30), new Product(3, 20)
));
Product p = products.stream().reduce(new Product(4, 0), (p1, p2) -> \{
p1.price += p2.price;
return new Product(p1.id, p1.price);
\});
products.add(p);
products.stream().parallel()
.reduce((p1, p2) -> p1.price > p2.price ? p1 : p2)
.ifPresent(System.out::println);
What is the result?
A 4:60 B 2:30 C 4:60 2:30 3:20 1:10 D 4:0 E The program prints nothing Show Answer Answer Explanation The first reduction accumulates the three prices into the identity product, yielding a product with id 4 and price 60. After that product is added to the list, the parallel reduction selects the product with the largest price, so it prints 4:60.
Given:
and this code fragment:
What is the outcome?
A User is registered. B An AgeOutOfLimitException is thrown. C A UserException is thrown. D A compilation error occurs in the doRegister method. Show Answer Answer Explanation The name has six characters and the age is 60, so neither exception condition is satisfied: the code checks for an age greater than 60, not greater than or equal to 60. The else branch executes and prints User is registered.
Given this 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 outcome?
A Searching... B Searching... Searching... C Searching... Searching... Searching... D A compilation error occurs. Show Answer Answer Explanation A Java lambda expression requires the -> token between its parameter list and body. Writing n - > separates that required token into the minus and greater-than operators, so the predicate declaration is invalid and compilation fails.
Learn more
Community Discussion