Java Certification Interview Questions & Answers

Top frequently asked interview questions with detailed answers, code examples, and expert tips.

75 Questions All Difficulty Levels Updated Mar 2026
1

What is the difference between JDK, JRE, and JVM? Easy

This is one of the most common Java certification questions. Understand it like a layered system:

  1. JVM (Java Virtual Machine): The engine that runs Java bytecode. It provides memory management, garbage collection, and execution.
  2. JRE (Java Runtime Environment): Everything needed to run Java apps: JVM + core libraries (rt.jar / modules) + runtime files.
  3. JDK (Java Development Kit): Everything needed to develop Java apps: JRE + compiler (javac) + tools like javadoc, jar, debugger.
Certification Tip: JDK ⟢ contains JRE ⟢ contains JVM.
jdk jre jvm basics certification
2

Why is Java platform-independent? Easy

Java is platform-independent because the source code is compiled into bytecode, not machine code.

  1. You compile: .java β†’ .class (bytecode)
  2. The bytecode runs on any system having a JVM.
  3. JVM converts bytecode to native instructions for that OS/CPU.
Key idea: β€œWrite Once, Run Anywhere” works because JVM exists on multiple platforms.
bytecode jvm wora
3

What is a class and object? Easy

Class is a blueprint, and object is a real instance created from that blueprint.

  1. Class defines fields + methods (state + behavior).
  2. Object occupies memory and has actual values.
Java
class Car { String color; void drive(){ } }
Car c = new Car();
Certification Tip: Many OCA/OCP questions test object creation and reference assignment.
oops class object
4

What is method overloading? Easy

Method overloading means multiple methods have the same name but different parameter lists.

  1. Different number of parameters OR
  2. Different types OR
  3. Different order of parameters

Note: Return type alone cannot overload a method.

overloading methods
5

What is method overriding? Easy

Method overriding happens when a child class provides a specific implementation of a method already defined in the parent class.

  1. Same method name
  2. Same parameters
  3. Child implementation is used at runtime (dynamic dispatch)
Certification Tip: Overriding is checked at runtime, overloading is compile-time.
overriding polymorphism
6

What is the difference between == and equals()? Easy

This is extremely important in certification exams:

  1. == checks whether two references point to the same object in memory.
  2. equals() checks logical equality (content) if overridden (e.g., String, wrappers).
Java
String a = new String("hi");
String b = new String("hi");
System.out.println(a==b);      // false
System.out.println(a.equals(b)); // true
equals strings objects
7

Why are Strings immutable in Java? Easy

Strings are immutable (cannot be changed) for multiple reasons:

  1. Security (e.g., file paths, class loading, SQL URLs)
  2. Thread-safety (safe sharing between threads)
  3. String Pool optimization (reuse same literal objects)
  4. Hashing stability (important for HashMap keys)
string immutability certification
8

Explain the String Pool. Easy

The String Pool is a special memory area where string literals are stored.

  1. Literals like "abc" go to pool.
  2. If same literal appears again, JVM reuses it.
  3. new String("abc") creates a new object in heap (different reference).
stringpool heap
9

What is autoboxing and unboxing? Easy

Autoboxing converts primitive β†’ wrapper automatically.

Unboxing converts wrapper β†’ primitive automatically.

Java
Integer x = 10; // autoboxing
int y = x;      // unboxing
Certification Tip: Watch out for NullPointerException during unboxing of null wrappers.
autoboxing wrappers
10

What is the difference between ArrayList and LinkedList? Easy

Both implement List but use different internal data structures:

  • ArrayList: dynamic array β†’ fast random access, slower inserts in middle
  • LinkedList: doubly linked list β†’ faster insert/delete in middle, slower random access
collections arraylist linkedlist
11

What is the purpose of final keyword? Easy

final prevents modifications depending on usage:

  1. final variable: value cannot change
  2. final method: cannot be overridden
  3. final class: cannot be inherited
final keyword
12

What is static keyword used for? Easy

static means member belongs to class, not to objects.

  1. static variables are shared across all objects
  2. static methods can be called without object
  3. static block runs once when class loads
static certification
13

What is a constructor? Easy

A constructor initializes an object when it is created.

  1. Same name as class
  2. No return type
  3. Can be overloaded
Certification Tip: If you do not write a constructor, compiler provides a default no-arg constructor (only when no constructors exist).
constructor oops
14

What is the difference between interface and abstract class? Easy

Both are used for abstraction, but differ:

  • Interface: contract (methods), can have default/static methods, supports multiple inheritance
  • Abstract class: can contain state (fields), constructors, and concrete methods
Certification Tip: Java allows multiple interfaces but single class inheritance.
interface abstract
15

Explain primitive data types in Java. Easy

Java has 8 primitives:

  • byte, short, int, long
  • float, double
  • char
  • boolean

All other types are reference types (objects).

primitives basics
16

What is the default value of instance variables? Easy

Instance variables get default values automatically:

  • int β†’ 0
  • boolean β†’ false
  • object reference β†’ null
  • char β†’ \u0000

Local variables do not get default values; they must be initialized before use.

variables defaults
17

What is an exception? Easy

An exception is an abnormal condition that interrupts program flow.

  1. Exceptions are objects derived from Throwable.
  2. Handled using try-catch-finally or thrown upward.
exceptions basics
18

Checked vs Unchecked exceptions? Easy

Checked exceptions must be handled/declared (compile-time), e.g., IOException.

Unchecked exceptions occur at runtime, derived from RuntimeException, e.g., NullPointerException.

exceptions checked unchecked
19

What is finally block? Easy

The finally block runs whether an exception occurs or not (almost always).

  • Used for cleanup: closing files, DB connections
Certification Tip: finally may not run if JVM exits via System.exit().
finally exceptions
20

What is a package in Java? Easy

A package is a namespace that organizes classes.

  • Avoids name conflicts
  • Improves maintainability
  • Controls access (default/package-private)
package namespace
21

Access modifiers in Java? Easy

Java has 4 access levels:

  • private: only within class
  • default: within package
  • protected: package + subclasses
  • public: accessible everywhere
access-modifiers oops
22

What is the difference between break and continue? Easy

break stops loop completely.

continue skips current iteration and moves to next.

loops control-flow
23

What is the difference between this and super? Easy

this refers to current object.

super refers to parent class.

  • super() calls parent constructor
  • super.method() calls parent method
this super inheritiance
24

What is type casting in Java? Easy

Type casting converts one type to another:

  1. Widening (safe): int β†’ long
  2. Narrowing (explicit): long β†’ int
Certification Tip: Many exam questions include tricky casting with char/byte.
casting types
25

What is the main method signature and why is it static? Easy

Standard signature:

Java
public static void main(String[] args)
  1. public: JVM must access it
  2. static: called without creating object
  3. void: does not return value
  4. String[] args: command line arguments
main-method basics
26

Explain method overriding rules in Java. Medium

Method overriding follows strict rules tested heavily in certification exams:

  1. Method name must be same.
  2. Parameters must be same.
  3. Return type must be same or covariant (subclass type).
  4. Access modifier cannot be more restrictive.
  5. Cannot throw broader checked exceptions than parent.
Certification Tip: private and static methods are not overridden - they are hidden.
overriding polymorphism certification
27

What is covariant return type? Medium

Covariant return type allows a subclass to return a more specific type when overriding.

Java
class A { A get(){ return this; } }
class B extends A { B get(){ return this; } }

Here B is allowed because it is a subclass of A.

covariant override
28

Explain pass-by-value in Java. Medium

Java is strictly pass-by-value.

  1. For primitives: actual value is copied.
  2. For objects: reference value is copied (not object itself).

That means method cannot change caller’s object reference, but can modify object’s internal state.

Exam Trick: Java is never pass-by-reference.
pass-by-value reference
29

Difference between HashMap and Hashtable? Medium

Key differences:

  • HashMap is not synchronized; Hashtable is synchronized.
  • HashMap allows one null key; Hashtable does not.
  • Hashtable is legacy class.
Certification Tip: Prefer ConcurrentHashMap over Hashtable in modern apps.
collections hashmap hashtable
30

Explain hashCode() and equals() contract. Medium

Important rules:

  1. If two objects are equal, they must have same hashCode().
  2. If hashCode differs, objects must be unequal.
  3. equals() must be reflexive, symmetric, transitive.

Violation leads to incorrect behavior in HashMap/HashSet.

hashcode equals collections
31

What is try-with-resources? Medium

Introduced in Java 7 to automatically close resources.

Java
try(FileInputStream f = new FileInputStream("a.txt")) {
  // use file
}

Resource must implement AutoCloseable interface.

exceptions resources
32

What is Comparable vs Comparator? Medium

Comparable provides natural ordering using compareTo().

Comparator provides custom ordering using compare().

Certification Tip: Comparator allows multiple sorting strategies.
comparable comparator collections
33

What is transient keyword? Medium

transient prevents a variable from being serialized.

When object is serialized, transient fields are skipped.

serialization transient
34

Explain the lifecycle of an object. Medium

Object lifecycle:

  1. Created using new keyword
  2. Used in application
  3. Becomes eligible for GC when no references exist
  4. Garbage collected
object-lifecycle gc
35

What is the difference between StringBuilder and StringBuffer? Medium

Both are mutable string classes:

  • StringBuffer is synchronized (thread-safe)
  • StringBuilder is not synchronized (faster)
Certification Tip: Prefer StringBuilder in single-threaded code.
stringbuilder stringbuffer
36

Explain static method hiding. Medium

Static methods are not overridden; they are hidden.

Method resolution depends on reference type, not object type.

Exam Trick: static methods use compile-time binding.
static hiding
37

What is instanceof operator? Medium

instanceof checks if object is instance of a class or interface.

Java
if(obj instanceof String){ }

Returns false for null.

instanceof type-check
38

Explain marker interfaces. Medium

Marker interface has no methods but marks a class.

Example: Serializable, Cloneable.

marker-interface serialization
39

What is cloning in Java? Medium

Cloning creates duplicate object using clone().

Class must implement Cloneable interface.

Certification Tip: clone() performs shallow copy by default.
clone object-copy
40

Explain shallow vs deep copy. Medium

Shallow copy: copies object but not nested objects.

Deep copy: copies object and all referenced objects.

copy clone
41

What is the difference between throw and throws? Medium

throw: used to explicitly throw exception.

throws: declares exceptions in method signature.

exceptions throw
42

What is functional interface? Medium

A functional interface has exactly one abstract method.

Example: Runnable, Comparator.

Certification Tip: Use @FunctionalInterface annotation.
functional-interface lambda
43

Explain lambda expression. Medium

Lambda provides concise implementation of functional interfaces.

Java
(a,b) -> a+b;

Introduced in Java 8.

lambda java8
44

What are default methods in interfaces? Medium

Default methods allow interface to have method implementation.

Introduced to maintain backward compatibility.

interface default-method
45

Explain Optional class. Medium

Optional prevents NullPointerException by wrapping values.

Java
Optional name = Optional.of("Java");
optional null-safety
46

What is Stream API? Medium

Stream API processes collections in functional style.

  • filter()
  • map()
  • collect()

Introduced in Java 8.

stream java8
47

What is method reference? Medium

Method reference is shorthand lambda using :: operator.

Java
System.out::println
method-reference lambda
48

Explain synchronization in Java. Medium

Synchronization ensures only one thread accesses critical section at a time.

Java
synchronized(this){ }
synchronization threads
49

What is volatile keyword? Medium

volatile ensures visibility of variable across threads.

Prevents caching in thread-local memory.

volatile concurrency
50

What is the difference between Runnable and Callable? Medium

Runnable: does not return result, cannot throw checked exception.

Callable: returns result, can throw checked exception.

threads callable runnable
51

Explain JVM memory structure in detail. Hard

JVM memory is divided into multiple areas:

  1. Heap - Stores objects and instance variables. Divided into Young, Old, and Metaspace (Java 8+).
  2. Stack - Stores method calls, local variables, and references.
  3. Method Area - Stores class metadata, static variables.
  4. PC Register - Keeps track of current instruction.
  5. Native Method Stack - For native methods.

Garbage Collection primarily works in Heap memory.

Certification Tip: Stack memory is thread-specific, Heap is shared.
jvm memory gc
52

Explain class loading process in Java. Hard

Class loading occurs in 3 main phases:

  1. Loading - ClassLoader loads bytecode into memory.
  2. Linking
    • Verification
    • Preparation
    • Resolution
  3. Initialization - Static variables and static blocks executed.

Bootstrap β†’ Extension β†’ Application ClassLoader hierarchy is used.

classloader jvm
53

Explain Garbage Collection algorithms. Hard

Major GC algorithms:

  • Mark and Sweep
  • Mark-Compact
  • Copying Collector
  • Generational GC
  • G1 GC

Young generation uses copying, old generation uses mark-sweep/compact.

Exam Focus: System.gc() does not guarantee GC.
gc jvm
54

What is memory leak in Java? Hard

Memory leak occurs when objects are no longer needed but still referenced.

Common causes:

  • Static collections
  • Listeners not removed
  • Unclosed resources

Tools like VisualVM and JProfiler help detect leaks.

memory-leak performance
55

Explain Thread lifecycle in Java. Hard

Thread states:

  1. New
  2. Runnable
  3. Blocked
  4. Waiting
  5. Timed Waiting
  6. Terminated

Managed by JVM scheduler.

threads lifecycle
56

What is Deadlock and how to prevent it? Hard

Deadlock occurs when two threads wait for each other’s resources.

Prevention strategies:

  • Avoid nested locks
  • Lock ordering
  • Use tryLock()
deadlock threads
57

Explain Java Memory Model (JMM). Hard

JMM defines interaction between threads and memory.

Key concepts:

  • Happens-before relationship
  • Visibility
  • Atomicity
  • Ordering

volatile and synchronized ensure visibility.

jmm concurrency
58

Explain ConcurrentHashMap internals. Hard

ConcurrentHashMap uses segmented locking (pre Java 8) and CAS operations (Java 8+).

Provides thread-safe operations without full synchronization.

collections concurrency
59

Difference between fail-fast and fail-safe iterators? Hard

Fail-fast: Throws ConcurrentModificationException (e.g., ArrayList).

Fail-safe: Works on clone copy (e.g., CopyOnWriteArrayList).

collections iterator
60

Explain CompletableFuture in detail. Hard

CompletableFuture enables asynchronous programming with chaining.

Java
CompletableFuture.supplyAsync(() -> "Hello")
.thenApply(s -> s + " World")
.thenAccept(System.out::println);

Supports non-blocking async workflows.

completablefuture async
61

What is ForkJoinPool? Hard

ForkJoinPool is used for parallelism using divide-and-conquer approach.

Uses work-stealing algorithm.

parallelism forkjoin
62

Explain reflection in Java. Hard

Reflection allows runtime inspection of classes and methods.

Java
Class c = Class.forName("MyClass");

Used in frameworks like Spring and Hibernate.

reflection framework
63

Explain Serialization internals. Hard

Serialization converts object to byte stream.

serialVersionUID ensures version compatibility.

Custom serialization via writeObject() and readObject().

serialization io
64

What is design pattern Singleton and its thread-safe implementation? Hard

Singleton ensures only one instance.

Java
public class Singleton {
  private static final Singleton instance = new Singleton();
  private Singleton(){}
  public static Singleton getInstance(){ return instance; }
}

Enum Singleton is safest approach.

design-pattern singleton
65

Explain Double Checked Locking. Hard

Used to reduce synchronization overhead.

Java
if(instance == null){
 synchronized(Class){
   if(instance == null) instance = new Obj();
 }
}

Requires volatile variable.

concurrency locking
66

What is MethodHandle and VarHandle? Hard

MethodHandle provides faster reflection alternative.

VarHandle gives access to variable with atomic operations.

methodhandle advanced
67

Explain NIO vs IO. Hard

IO: Blocking, stream-based.

NIO: Non-blocking, buffer-based.

NIO uses channels and selectors.

nio performance
68

What is Stream parallel processing? Hard

Stream API supports parallel execution.

Java
list.parallelStream().forEach(System.out::println);

Uses ForkJoinPool.

stream parallel
69

Explain volatile vs synchronized in depth. Hard

volatile ensures visibility.

synchronized ensures visibility + atomicity.

volatile does not provide atomic operations.

volatile synchronized
70

Explain weak references and soft references. Hard

Strong: Normal reference.

Soft: GC when memory low.

Weak: GC immediately when no strong reference.

memory gc reference
71

Explain immutable class design in Java. Hard

Steps to create immutable class:

  1. Declare class final
  2. All fields private final
  3. No setters
  4. Return defensive copies

Example: String class.

immutable design
72

Explain Executor framework. Hard

Executor framework manages thread pools.

Java
ExecutorService ex = Executors.newFixedThreadPool(5);

Provides better resource management.

executor threads
73

What is atomic variable? Hard

Atomic classes provide lock-free thread-safe programming.

Example: AtomicInteger.

atomic concurrency
74

Explain Java module system (Java 9). Hard

Module system groups packages into modules.

module-info.java defines dependencies.

modules java9
75

Explain how JVM optimizes bytecode. Hard

JVM uses JIT (Just-In-Time) compiler.

  • Inlining
  • Escape Analysis
  • Loop Unrolling
  • Dead Code Elimination

HotSpot optimizes frequently executed code.

jit jvm optimization
πŸ“Š Questions Breakdown
🟒 Easy 25
🟑 Medium 25
πŸ”΄ Hard 25
πŸŽ“ Master Java Certification Training

Join our live classes with expert instructors and hands-on projects.

Enroll Now

What People Say

Testimonial

Nagmani Solanki

Digital Marketing

Edugators platform is the best place to learn live classes, and live projects by which you can understand easily and have excellent customer service.

Testimonial

Saurabh Arya

Full Stack Developer

It was a very good experience. Edugators and the instructor worked with us through the whole process to ensure we received the best training solution for our needs.

testimonial

Praveen Madhukar

Web Design

I would definitely recommend taking courses from Edugators. The instructors are very knowledgeable, receptive to questions and willing to go out of the way to help you.

Need To Train Your Corporate Team ?

Customized Corporate Training Programs and Developing Skills For Project Success.

Google AdWords Training
React Training
Angular Training
Node.js Training
AWS Training
DevOps Training
Python Training
Hadoop Training
Photoshop Training
CorelDraw Training
.NET Training

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators