O'Reilly logo

OCP Oracle® Certified Professional Java® SE 8 Programmer II by Scott Selikoff, Jeanne Boyarsky

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Assessment Test

  1. What is the result of executing the following application? (Choose all that apply.)

    import java.util.concurrent.*;
    import java.util.stream.*;
    public class BabyPandaBathManager {
       public static void await(CyclicBarrier cb) {
          try {
             cb.await();
          } catch (InterruptedException | BrokenBarrierException e) {
             // Handle exception
          }
       }
       public static void main(String[] args) {
          final CyclicBarrier cb = new CyclicBarrier(3,()-> System.out.println("Clean!"));// u1
          ExecutorService service = Executors.newScheduledThreadPool(2);
          IntStream.iterate(1, i-> 1) // u2
             .limit(12)
             .forEach(i-> service.submit( // u3
                   ()-> await(cb))); // u4
          service.shutdown();
       }
    }
    1. It outputs Clean! at least once.
    2. It outputs Clean! four times.
    3. The code will not compile because of line u1.
    4. The code will not compile because of line u2.
    5. The code will not compile because of line u3.
    6. The code will not compile because of line u4.
    7. It compiles but throws an exception at runtime.
    8. It compiles but waits forever at runtime.
  2. What is the result of the following program?

    1:    public abstract class Message {
    2:       public String recipient;
    3:       public abstract final void sendMessage();
    4:       public static void main(String[] args) {
    5:          Message m = new TextMessage();
    6:          m.recipient = "1234567890";
    7:          m.sendMessage();
    8:       }
    9:       static class TextMessage extends Message {
    10:         public final void sendMessage() {
    11:            System.out.println("Text message to " + recipient);
    12:         } } }
    1. Text message to null.
    2. Text message to 1234567890.
    3. A compiler ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required