Oracle Certified Professional Java Se 8 Programmer Exam Questions & Answers

Practice 54 free Oracle Certified Professional Java Se 8 Programmer exam questions with answers and community-discussed explanations. Each question has its own page where you can reveal the correct answer and debate it in the comments.

All 54 questions

  1. Q1 Given structure of LOG table: LOG (ID integer, MESSAGE varchar(1000), PRIMARY KEY (ID)) Given code of Test.java file: package com.udayan.ocp; import java.sql.*;import java.util.Properties; public class Test {…
  2. Q2 Given structure of EMPLOYEE table: EMPLOYEE (ID integer, FIRSTNAME varchar(100), LASTNAME varchar(100), SALARY real, PRIMARY KEY (ID)) EMPLOYEE table contains below records: 101 John Smith…
  3. Q3 Given code of Test.java file: package com.udayan.ocp; import java.util.Arrays;import java.util.Collections;import java.util.List; public class Test { public static void main(String[] args) { List<String> list = Arrays.asList("M",…
  4. Q4 Given code of Test.java file:  package com.udayan.ocp; import java.io.*;import java.nio.file.Path;import java.nio.file.Paths; public class Test { public static void main(String[] args) throws IOException { Path…
  5. Q5 Consider below code of Child.java file: package com.udayan.ocp; class Parent { public void m() { System.out.println("Parent"); }} public abstract class Child extends Parent { //Line…
  6. Q6 Below is the code of Test.java file: package com.udayan.ocp; public class Test { public static void main(String [] args) { System.out.println(new Object() {…
  7. Q7 Given code of Test.java file: package com.udayan.ocp; import java.util.stream.Stream; public class Test { public static void main(String[] args) { Stream<Double> stream = Stream.generate(() -> new…
  8. Q8 Consider the code of Test.java file:package com.udayan.ocp; class Player { String name; int age;  Player() { this.name = "Sachin"; this.age = 44; } …
  9. Q9 Given code of Test.java file:package com.udayan.ocp; public class Test { private static final <X extends Integer, Y extends Integer> void add(X x, Y…
  10. Q10 Given structure of EMPLOYEE table: EMPLOYEE (ID integer, FIRSTNAME varchar(100), LASTNAME varchar(100), SALARY real, PRIMARY KEY (ID)) EMPLOYEE table contains below records: 101 John Smith…
  11. Q11 Imagine below path exists: F:.└───A └───B     Given code of Test.java file:  package com.udayan.ocp; import java.io.*; public class Test { public static void main(String[]…
  12. Q12 Given code:package com.udayan.ocp; enum TrafficLight { RED, YELLOW, GREEN;} public class Test { public static void main(String[] args) { TrafficLight tl1 = TrafficLight.GREEN; TrafficLight…
  13. Q13 Given code of Test.java file:  package com.udayan.ocp; import java.io.*; public class Test { public static void main(String[] args) { try(BufferedWriter bw = new BufferedWriter(new…
  14. Q14 Given code of Test.java file: package com.udayan.ocp; public class Test<T> { private T t;  public T get() { return t; }  public void set(T…
  15. Q15 Given code of Test.java file:package com.udayan.ocp; import java.util.function.Supplier; public class Test { public static void main(String[] args) { Supplier<StringBuilder> supplier = () -> new…
  16. Q16 Consider the code of Test.java file: package com.udayan.ocp; class Point { private int x; private int y;  Point(){ Point(10, 20); }  Point(int x,…
  17. Q17 Given code of Test.java file: package com.udayan.ocp; import java.util.Optional; public class Test { public static void main(String[] args) { Optional<Integer> optional = Optional.of(null); //Line 8…
  18. Q18 What will be the result of compiling and executing Test class?package com.udayan.ocp; import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.List; class Point { private int x; private…
  19. Q19 Given code of Test.java file:  package com.udayan.ocp; import java.util.Arrays;import java.util.List;import java.util.function.Predicate; public class Test { public static void main(String[] args) { List<Integer> list =…
  20. Q20 Given code of Test.java file:  package com.udayan.ocp; import java.util.List;import java.util.Map;import java.util.stream.Collectors;import java.util.stream.Stream; class Certification { String studId; String test; int marks;  Certification(String studId, String…
  21. Q21 Given code of Test.java file:package com.udayan.ocp; import java.util.*; class Employee { private String name; private double salary;  public Employee(String name, double salary) { this.name…
  22. Q22 Given code of Test.java file: package com.udayan.ocp; import java.util.ArrayList;import java.util.List; public class Test { public static void main(String[] args) { int ref = 10; List<Integer>…
  23. Q23 Given code:  package com.udayan.ocp; class Outer { private String name = "James Gosling"; //Insert inner class definition here} public class Test { public static…
  24. Q24 Given code of Test.java file:  package com.udayan.ocp; import java.util.stream.IntStream; public class Test { public static void main(String[] args) { int sum = IntStream.rangeClosed(1,3).map(i ->…
  25. Q25 Consider the code of Test.java file: package com.udayan.ocp; enum Flags { TRUE, FALSE;  Flags() { System.out.println("HELLO"); }} public class Test { public static void…
  26. Q26 F: is accessible for reading/writing and below is the directory structure for F:F:.└───A └───B Book.javaBook.java is a text file.       …
  27. Q27 Given code of Test.java file:  package com.udayan.ocp; import java.util.stream.Stream; public class Test { public static void main(String[] args) { Stream<Integer> stream = Stream.iterate(1, i…
  28. Q28 Given code of Test.java file:  package com.udayan.ocp; import java.util.OptionalDouble; class MyException extends RuntimeException{} public class Test { public static void main(String[] args) { OptionalDouble optional…
  29. Q29 Given code of Test.java file:  package com.udayan.ocp; import java.nio.file.Path;import java.nio.file.Paths; public class Test { public static void main(String[] args) { Path path1 = Paths.get("F:\\A\\B\\C");…
  30. Q30 Below is the code to Test.java file: package com.udayan.ocp; enum ShapeType { CIRCLE, SQUARE, RECTANGLE;} abstract class Shape { private ShapeType type = ShapeType.SQUARE;…
  31. Q31 Given code of Test.java file: package com.udayan.ocp; import java.util.Arrays;import java.util.Comparator;import java.util.List; class Student implements Comparator<Student> { private String name; private String exam;  public Student() {…
  32. Q32 Given code of Test.java file: package com.udayan.ocp; import java.util.ArrayList;import java.util.List; public class Test { public static void main(String[] args) { int ref = 10; List<Integer>…
  33. Q33 Given code of Test.java file:  package com.udayan.ocp; import java.util.*; public class Test { public static void main(String[] args) { NavigableMap<Integer, String> map = new…
  34. Q34 Performance with parallel stream is always better than sequential streams.
  35. Q35 Which of the following code will create/return a Locale object for the JVM, on which your code is running?
  36. Q36 Given: package com.udayan.ocp; import java.util.function.Supplier; class Document { void printAuthor() { System.out.println("Document-Author"); }} class RFP extends Document { @Override void printAuthor() { System.out.println("RFP-Author"); }} public class…
  37. Q37 Given code: package com.udayan.ocp; public class Test { class A { void m() { System.out.println("INNER"); } } public static void main(String [] args) {…
  38. Q38 Which of the following will always represent Locale object for English in US? Select 2 options.
  39. Q39 Given code of Test.java file:package com.udayan.ocp; import java.util.Arrays;import java.util.Collections;import java.util.Comparator;import java.util.List; public class Test { public static void main(String[] args) { List<String> list =…
  40. Q40 Given code of Test.java file:package com.udayan.ocp; import java.util.function.BiFunction; public class Test { public static void main(String[] args) { BiFunction<Integer, Integer, Character> compFunc = (i,…
  41. Q41 Given code:  package com.udayan.ocp; class Printer<T implements Cloneable> {} public class Test { public static void main(String[] args) { Printer<String> printer = new Printer<>();…
  42. Q42 Given code of Test.java file:  package com.udayan.ocp; public class Test { private static void checkStatus(boolean flag) { assert flag : flag = true;…
  43. Q43 Given code of Test.java file: package com.udayan.ocp; import java.util.ArrayDeque;import java.util.Deque; public class Test { public static void main(String[] args) { Deque<Character> chars = new ArrayDeque<>();…
  44. Q44 Given code of Test.java file:  package com.udayan.ocp; import java.time.*; public class Test { public static void main(String [] args) { System.out.println(Duration.ofDays(-2)); }} What will…
  45. Q45 Consider the code of Test.java file: package com.udayan.ocp; public class Test { enum Directions { NORTH("N"), SOUTH("S"), EAST("E"), WEST("W")  private String notation;  Directions(String…
  46. Q46 Given code of Test.java file: package com.udayan.ocp; import java.time.*; public class Test { public static void main(String [] args) { LocalTime t1 = LocalTime.now();…
  47. Q47 Given structure of MESSAGES table:MESSAGES (msg1 varchar(100), msg2 varchar(100)) MESSAGES table contains below records: 'Happy New Year!', 'Happy Holidays!'Given code of Test.java file: package…
  48. Q48 Given Code: package com.udayan.ocp; import java.io.*; class ReadTheFile { static void print() { //Line 4 throw new IOException(); //Line 5 }} public class Test {…
  49. Q49 Given code of Test.java file: package com.udayan.ocp; import java.util.Arrays;import java.util.List; public class Test { public static void main(String[] args) { List<Integer> list = Arrays.asList(0,2,4,6,8); list.replaceAll(i…
  50. Q50 Given code of Test.java file:  package com.udayan.ocp; import java.util.Comparator;import java.util.stream.Stream; public class Test { public static void main(String[] args) { Stream<String> stream = Stream.of("d",…
  51. Q51 Given code of Test.java file: package com.udayan.ocp; import java.util.ArrayList;import java.util.Collections;import java.util.List;import java.util.stream.IntStream; public class Test { public static void main(String[] args) { List<Integer> list…
  52. Q52 Given code of Test.java file:  package com.udayan.ocp; import java.io.IOException;import java.nio.file.Files;import java.nio.file.Path;import java.nio.file.Paths;import java.util.stream.Stream; public class Test { public static void main(String[] args) throws IOException…
  53. Q53 Given code of Test.java file: package com.udayan.ocp; class MyException1 extends RuntimeException {} class MyException2 extends RuntimeException {} public class Test { private static void m()…
  54. Q54 Given structure of EMPLOYEE table: EMPLOYEE (ID integer, FIRSTNAME varchar(100), LASTNAME varchar(100), SALARY real, PRIMARY KEY (ID)) EMPLOYEE table contains below records: 101 John Smith…

More Oracle certifications

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need