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:
javac) + tools like javadoc, jar, debugger.Why is Java platform-independent? Easy
Java is platform-independent because the source code is compiled into bytecode, not machine code.
.java β .class (bytecode)What is a class and object? Easy
Class is a blueprint, and object is a real instance created from that blueprint.
class Car { String color; void drive(){ } }
Car c = new Car();What is method overloading? Easy
Method overloading means multiple methods have the same name but different parameter lists.
Note: Return type alone cannot overload a method.
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.
What is the difference between == and equals()? Easy
This is extremely important in certification exams:
String a = new String("hi");
String b = new String("hi");
System.out.println(a==b); // false
System.out.println(a.equals(b)); // trueWhy are Strings immutable in Java? Easy
Strings are immutable (cannot be changed) for multiple reasons:
Explain the String Pool. Easy
The String Pool is a special memory area where string literals are stored.
"abc" go to pool.new String("abc") creates a new object in heap (different reference).What is autoboxing and unboxing? Easy
Autoboxing converts primitive β wrapper automatically.
Unboxing converts wrapper β primitive automatically.
Integer x = 10; // autoboxing int y = x; // unboxing
What is the difference between ArrayList and LinkedList? Easy
Both implement List but use different internal data structures:
What is the purpose of final keyword? Easy
final prevents modifications depending on usage:
What is static keyword used for? Easy
static means member belongs to class, not to objects.
What is a constructor? Easy
A constructor initializes an object when it is created.
What is the difference between interface and abstract class? Easy
Both are used for abstraction, but differ:
Explain primitive data types in Java. Easy
Java has 8 primitives:
All other types are reference types (objects).
What is the default value of instance variables? Easy
Instance variables get default values automatically:
Local variables do not get default values; they must be initialized before use.
What is an exception? Easy
An exception is an abnormal condition that interrupts program flow.
Throwable.try-catch-finally or thrown upward.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.
What is finally block? Easy
The finally block runs whether an exception occurs or not (almost always).
What is a package in Java? Easy
A package is a namespace that organizes classes.
Access modifiers in Java? Easy
Java has 4 access levels:
What is the difference between break and continue? Easy
break stops loop completely.
continue skips current iteration and moves to next.
What is the difference between this and super? Easy
this refers to current object.
super refers to parent class.
What is type casting in Java? Easy
Type casting converts one type to another:
What is the main method signature and why is it static? Easy
Standard signature:
public static void main(String[] args)
Explain method overriding rules in Java. Medium
Method overriding follows strict rules tested heavily in certification exams:
What is covariant return type? Medium
Covariant return type allows a subclass to return a more specific type when overriding.
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.
Explain pass-by-value in Java. Medium
Java is strictly pass-by-value.
That means method cannot change callerβs object reference, but can modify objectβs internal state.
Difference between HashMap and Hashtable? Medium
Key differences:
Explain hashCode() and equals() contract. Medium
Important rules:
Violation leads to incorrect behavior in HashMap/HashSet.
What is try-with-resources? Medium
Introduced in Java 7 to automatically close resources.
try(FileInputStream f = new FileInputStream("a.txt")) {
// use file
}Resource must implement AutoCloseable interface.
What is Comparable vs Comparator? Medium
Comparable provides natural ordering using compareTo().
Comparator provides custom ordering using compare().
What is transient keyword? Medium
transient prevents a variable from being serialized.
When object is serialized, transient fields are skipped.
Explain the lifecycle of an object. Medium
Object lifecycle:
What is the difference between StringBuilder and StringBuffer? Medium
Both are mutable string classes:
Explain static method hiding. Medium
Static methods are not overridden; they are hidden.
Method resolution depends on reference type, not object type.
What is instanceof operator? Medium
instanceof checks if object is instance of a class or interface.
if(obj instanceof String){ }Returns false for null.
Explain marker interfaces. Medium
Marker interface has no methods but marks a class.
Example: Serializable, Cloneable.
What is cloning in Java? Medium
Cloning creates duplicate object using clone().
Class must implement Cloneable interface.
Explain shallow vs deep copy. Medium
Shallow copy: copies object but not nested objects.
Deep copy: copies object and all referenced objects.
What is the difference between throw and throws? Medium
throw: used to explicitly throw exception.
throws: declares exceptions in method signature.
What is functional interface? Medium
A functional interface has exactly one abstract method.
Example: Runnable, Comparator.
Explain lambda expression. Medium
Lambda provides concise implementation of functional interfaces.
(a,b) -> a+b;
Introduced in Java 8.
What are default methods in interfaces? Medium
Default methods allow interface to have method implementation.
Introduced to maintain backward compatibility.
Explain Optional class. Medium
Optional prevents NullPointerException by wrapping values.
Optionalname = Optional.of("Java");
What is Stream API? Medium
Stream API processes collections in functional style.
Introduced in Java 8.
What is method reference? Medium
Method reference is shorthand lambda using :: operator.
System.out::println
Explain synchronization in Java. Medium
Synchronization ensures only one thread accesses critical section at a time.
synchronized(this){ }What is volatile keyword? Medium
volatile ensures visibility of variable across threads.
Prevents caching in thread-local memory.
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.
Explain JVM memory structure in detail. Hard
JVM memory is divided into multiple areas:
Garbage Collection primarily works in Heap memory.
Explain class loading process in Java. Hard
Class loading occurs in 3 main phases:
Bootstrap β Extension β Application ClassLoader hierarchy is used.
Explain Garbage Collection algorithms. Hard
Major GC algorithms:
Young generation uses copying, old generation uses mark-sweep/compact.
What is memory leak in Java? Hard
Memory leak occurs when objects are no longer needed but still referenced.
Common causes:
Tools like VisualVM and JProfiler help detect leaks.
Explain Thread lifecycle in Java. Hard
Thread states:
Managed by JVM scheduler.
What is Deadlock and how to prevent it? Hard
Deadlock occurs when two threads wait for each otherβs resources.
Prevention strategies:
Explain Java Memory Model (JMM). Hard
JMM defines interaction between threads and memory.
Key concepts:
volatile and synchronized ensure visibility.
Explain ConcurrentHashMap internals. Hard
ConcurrentHashMap uses segmented locking (pre Java 8) and CAS operations (Java 8+).
Provides thread-safe operations without full synchronization.
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).
Explain CompletableFuture in detail. Hard
CompletableFuture enables asynchronous programming with chaining.
CompletableFuture.supplyAsync(() -> "Hello") .thenApply(s -> s + " World") .thenAccept(System.out::println);
Supports non-blocking async workflows.
What is ForkJoinPool? Hard
ForkJoinPool is used for parallelism using divide-and-conquer approach.
Uses work-stealing algorithm.
Explain reflection in Java. Hard
Reflection allows runtime inspection of classes and methods.
Class c = Class.forName("MyClass");Used in frameworks like Spring and Hibernate.
Explain Serialization internals. Hard
Serialization converts object to byte stream.
serialVersionUID ensures version compatibility.
Custom serialization via writeObject() and readObject().
What is design pattern Singleton and its thread-safe implementation? Hard
Singleton ensures only one instance.
public class Singleton {
private static final Singleton instance = new Singleton();
private Singleton(){}
public static Singleton getInstance(){ return instance; }
}Enum Singleton is safest approach.
Explain Double Checked Locking. Hard
Used to reduce synchronization overhead.
if(instance == null){
synchronized(Class){
if(instance == null) instance = new Obj();
}
}Requires volatile variable.
What is MethodHandle and VarHandle? Hard
MethodHandle provides faster reflection alternative.
VarHandle gives access to variable with atomic operations.
Explain NIO vs IO. Hard
IO: Blocking, stream-based.
NIO: Non-blocking, buffer-based.
NIO uses channels and selectors.
What is Stream parallel processing? Hard
Stream API supports parallel execution.
list.parallelStream().forEach(System.out::println);
Uses ForkJoinPool.
Explain volatile vs synchronized in depth. Hard
volatile ensures visibility.
synchronized ensures visibility + atomicity.
volatile does not provide atomic operations.
Explain weak references and soft references. Hard
Strong: Normal reference.
Soft: GC when memory low.
Weak: GC immediately when no strong reference.
Explain immutable class design in Java. Hard
Steps to create immutable class:
Example: String class.
Explain Executor framework. Hard
Executor framework manages thread pools.
ExecutorService ex = Executors.newFixedThreadPool(5);
Provides better resource management.
What is atomic variable? Hard
Atomic classes provide lock-free thread-safe programming.
Example: AtomicInteger.
Explain Java module system (Java 9). Hard
Module system groups packages into modules.
module-info.java defines dependencies.
Explain how JVM optimizes bytecode. Hard
JVM uses JIT (Just-In-Time) compiler.
HotSpot optimizes frequently executed code.
Join our live classes with expert instructors and hands-on projects.
Enroll NowCustomized Corporate Training Programs and Developing Skills For Project Success.
Subscibe to our newsletter and we will notify you about the newest updates on Edugators