Java Programmer Certification Exam Q&A: Practice Questions and Rationales, Exams of Java Programming

A set of practice questions and answers for the oracle certified professional java programmer examination. Each question is followed by the correct answer and a rationale explaining why that answer is correct. This resource is designed to help candidates prepare for the certification exam by testing their knowledge of java programming concepts and providing clear explanations of the underlying principles. The questions cover a range of topics, including java basics, object-oriented programming, collections, multithreading, and exception handling. Useful for university students, high school students and lifelong learners.

Typology: Exams

2025/2026

Available from 12/19/2025

masterystudyhub
masterystudyhub 🇺🇸

4.7

(3)

4.4K documents

1 / 25

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ORACLE CERTIFIED PROFESSIONAL JAVA
PROGRAMMER EXAMINATION
QUESTION AND CORRECT ANSWERS
(VERIFIED ANSWERS) PLUS RATIONALES
2026 Q&A INSTANT DOWNLOAD PDF
1. Which of the following best describes Java’s platform independence?
A. Java programs run only on Linux
B. Java programs are compiled directly to machine code
C. Java programs require recompilation for each OS
D. Java programs run on any system with a JVM
D
Java source code is compiled into bytecode, which runs on any platform
that has a Java Virtual Machine (JVM).
2. What is the default value of an instance variable of type int?
A. 1
B. -1
C. 0
D. null
C
Instance variables of numeric primitive types default to 0 if not explicitly
initialized.
3. Which keyword prevents a class from being inherited?
A. static
B. private
C. final
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19

Partial preview of the text

Download Java Programmer Certification Exam Q&A: Practice Questions and Rationales and more Exams Java Programming in PDF only on Docsity!

ORACLE CERTIFIED PROFESSIONAL JAVA

PROGRAMMER EXAMINATION

QUESTION AND CORRECT ANSWERS

(VERIFIED ANSWERS) PLUS RATIONALES

2026 Q&A INSTANT DOWNLOAD PDF

  1. Which of the following best describes Java’s platform independence? A. Java programs run only on Linux B. Java programs are compiled directly to machine code C. Java programs require recompilation for each OS D. Java programs run on any system with a JVM D Java source code is compiled into bytecode, which runs on any platform that has a Java Virtual Machine (JVM).
  2. What is the default value of an instance variable of type int? A. 1 B. - 1 C. 0 D. null C Instance variables of numeric primitive types default to 0 if not explicitly initialized.
  3. Which keyword prevents a class from being inherited? A. static B. private C. final

D. abstract C A class declared as final cannot be extended by another class.

  1. What happens if a local variable is used without initialization? A. It gets a default value B. The compiler assigns null C. Runtime exception occurs D. Compilation error D Local variables must be explicitly initialized before use, or compilation fails.
  2. Which access modifier allows visibility only within the same package? A. public B. private C. protected D. default D The default (package-private) access level allows access only within the same package.
  3. Which collection does not allow duplicate elements? A. List B. Set C. Queue D. Map B Set implementations enforce uniqueness of elements.
  4. What is the parent class of all Java classes? A. Object B. Class C. System D. Runtime

B

Java char is a 16-bit Unicode character. 12.Which interface must be implemented to create a thread? A. Serializable B. Runnable C. AutoCloseable D. Cloneable B Runnable provides the run() method for thread execution. 13.What happens when equals() is not overridden? A. Reference comparison is used B. Value comparison is used C. Compilation error D. Runtime exception A Object.equals() compares object references unless overridden. 14.Which exception is unchecked? A. IOException B. SQLException C. ClassNotFoundException D. NullPointerException D Unchecked exceptions extend RuntimeException. 15.Which keyword ensures only one instance of a variable per class? A. final B. transient C. static D. volatile C Static variables belong to the class rather than instances.

16.Which loop executes at least once? A. for B. while C. do-while D. enhanced for C The do-while loop evaluates the condition after executing the body. 17.Which package is automatically imported in every Java program? A. java.io B. java.util C. java.lang D. java.net C java.lang is imported implicitly by the compiler. 18.Which statement about interfaces is true? A. They can have instance variables B. They support multiple inheritance C. They can have constructors D. They must be final B Interfaces allow multiple inheritance of behavior. 19.What is polymorphism? A. Using multiple classes B. Method hiding C. Same reference, different behavior D. Code duplication C Polymorphism allows an object to be treated as its superclass type while exhibiting subclass behavior. 20.Which keyword prevents method overriding? A. static

C. Multiple inheritance D. Method overloading B Encapsulation restricts direct access to data using access modifiers. 25.Which operator compares object references? A. equals() B. == C. instanceof D. compareTo() B The == operator checks reference equality. 26.What is autoboxing? A. Manual conversion of objects B. Automatic conversion between primitives and wrappers C. Serialization process D. Casting objects B Autoboxing automatically wraps primitives into their wrapper classes. 27.Which class is immutable? A. String B. StringBuilder C. StringBuffer D. ArrayList A String objects cannot be modified after creation. 28.Which collection maintains insertion order? A. HashSet B. TreeSet C. LinkedHashSet D. PriorityQueue

C

LinkedHashSet preserves insertion order. 29.What does the transient keyword do? A. Makes variable volatile B. Excludes variable from serialization C. Makes variable constant D. Makes variable thread-safe B Transient fields are not serialized. 30.Which statement about abstract classes is true? A. They cannot have constructors B. They cannot have concrete methods C. They can have instance variables D. They must be final C Abstract classes can contain fields, constructors, and concrete methods. 31.Which feature was introduced in Java 8? A. Generics B. Lambda expressions C. Multithreading D. Applets B Lambda expressions were added in Java 8 to support functional programming. 32.Which interface represents a functional interface? A. Runnable B. Serializable C. Cloneable D. RandomAccess

37.Which collection sorts elements naturally? A. HashMap B. LinkedList C. TreeSet D. ArrayList C TreeSet sorts elements according to natural ordering or comparator. 38.What is garbage collection? A. Manual memory cleanup B. Automatic memory management C. Stack cleanup D. File deletion B Garbage collection automatically frees unused objects. 39.Which keyword is used to inherit a class? A. implements B. extends C. super D. this B The extends keyword creates an inheritance relationship. 40.Which statement about static methods is true? A. They can access instance variables directly B. They belong to instances C. They can be overridden D. They belong to the class D Static methods are associated with the class, not instances.

41.Which map allows null keys? A. TreeMap B. Hashtable C. HashMap D. ConcurrentHashMap C HashMap allows one null key and multiple null values. 42.Which exception occurs when dividing by zero? A. IOException B. ArithmeticException C. NumberFormatException D. IllegalArgumentException B Division by zero for integers throws ArithmeticException. 43.Which feature ensures one thread executes at a time? A. Serialization B. Synchronization C. Inheritance D. Polymorphism B Synchronization controls concurrent access to shared resources. 44.Which class loader loads core Java classes? A. Extension ClassLoader B. System ClassLoader C. Bootstrap ClassLoader D. Custom ClassLoader C Bootstrap ClassLoader loads core Java libraries. 45.Which statement about enums is true? A. They cannot have methods B. They extend Object implicitly

A

Character is the wrapper class for char. 50.Which collection is best for fast random access? A. LinkedList B. HashSet C. ArrayList D. TreeSet C ArrayList provides constant-time positional access. 51.What is a marker interface? A. Interface with default methods B. Interface with one method C. Interface with no methods D. Interface with static methods C Marker interfaces signal metadata to the JVM or APIs. 52.Which statement about constructors is false? A. They can be overloaded B. They can be private C. They can be overridden D. They initialize objects C Constructors cannot be overridden. 53.Which exception indicates array index out of bounds? A. IndexOutOfBoundsException B. ArrayIndexOutOfBoundsException C. IllegalArgumentException D. RuntimeException

B

ArrayIndexOutOfBoundsException is thrown for invalid array indices. 54.Which feature allows multiple forms of a method? A. Overloading B. Overriding C. Encapsulation D. Abstraction A Overloading allows methods with same name but different parameters. 55.Which class is thread-safe? A. ArrayList B. HashMap C. Vector D. LinkedList C Vector methods are synchronized by default. 56.Which keyword is used to explicitly throw an exception? A. throws B. catch C. throw D. finally C throw explicitly throws an exception object. 57.Which data structure uses FIFO? A. Stack B. Queue C. Set D. Map B Queue follows First-In-First-Out order.

62.Which interface provides compareTo()? A. Comparator B. Comparable C. Serializable D. Iterable B Comparable defines natural ordering via compareTo(). 63.Which class provides dynamic arrays? A. Vector B. Array C. ArrayList D. LinkedList C ArrayList resizes dynamically. 64.Which statement about packages is true? A. They cannot be nested B. They group related classes C. They prevent compilation D. They replace imports B Packages organize related classes and interfaces. 65.Which Java keyword creates an object? A. class B. new C. this D. super B The new keyword allocates memory for objects. 66.Which exception is thrown when casting fails? A. ClassCastException B. IllegalStateException

C. NullPointerException D. NumberFormatException A Invalid casting results in ClassCastException. 67.Which Java feature supports multiple inheritance indirectly? A. Classes B. Abstract classes C. Interfaces D. Enums C Interfaces allow a class to implement multiple types. 68.Which method starts a thread? A. run() B. start() C. execute() D. begin() B start() creates a new thread and invokes run(). 69.Which class is used to read text files efficiently? A. FileInputStream B. BufferedReader C. Scanner D. DataInputStream B BufferedReader provides efficient reading of text. 70.Which statement about lambda expressions is true? A. They require abstract classes B. They replace loops C. They implement functional interfaces D. They cannot access variables

C

Final prevents overriding. 75.Which feature binds method calls at runtime? A. Static binding B. Compile-time binding C. Dynamic binding D. Early binding C Dynamic binding supports polymorphism. 76.Which class handles dates in legacy Java? A. Date B. LocalDate C. Calendar D. Time A java.util.Date represents date and time in legacy APIs. 77.Which operator is short-circuit AND? A. & B. && C. | D. || B && evaluates the second operand only if needed. 78.Which method converts object to string? A. hashCode() B. equals() C. toString() D. valueOf() C toString() returns a string representation.

79.Which Java feature supports loose coupling? A. Inheritance B. Encapsulation C. Interfaces D. Overloading C Interfaces reduce dependency between implementations. 80.Which keyword allows subclass access within packages? A. private B. protected C. default D. public B Protected allows access in subclasses and same package. 81.Which class is used for immutable sequences of characters? A. StringBuilder B. StringBuffer C. String D. CharArray C String objects are immutable. 82.Which exception indicates missing class at runtime? A. ClassNotFoundException B. NoClassDefFoundError C. IOException D. InstantiationException B NoClassDefFoundError occurs when class definition is missing at runtime.