Below are concise interview‑ready answers to all questions from your notes, each with clear
explanations and small code snippets where relevant.
CORE JAVA CONCEPTS
1) Difference between JDK and JRE
JDK = JRE + Development tools (javac, debugger). Used for development. JRE = JVM + Libraries. Used to run
Java programs.
JDK = JRE + Compiler + Tools
JRE = JVM + Libraries
2) Why Java is platform independent
Java compiles into bytecode, which runs on JVM available for different OS.
.java → javac → .class (bytecode) → JVM → OS
3) Abstract class vs Interface
Abstract class can have implementation + state. Interface supports multiple inheritance and defines
contracts.
abstract class A { abstract void run(); }
interface B { void run(); }
4) final vs finally vs finalize
• final: constant / no override / no inheritance
• finally: always executes
• finalize: GC cleanup (deprecated)
final int x = 10;
try {} finally {}
1
5) Stack vs Heap memory
Stack → method calls, local variables (LIFO) Heap → objects, shared
int x = 10; // stack
User u = new User(); // heap
6) Method Overloading vs Overriding
Overloading → same method name, different params (compile‑time) Overriding → same signature, child
class (runtime)
void add(int a);
void add(int a,int b);
7) Abstract class vs Interface (deep)
Abstract class allows constructors. Interface supports default & static methods.
interface I { default void show(){} }
8) private vs protected
private → same class only protected → same package + subclasses
private int x;
protected int y;
9) Constructor Overloading
Multiple constructors with different parameters.
class A{
A(){}
2
A(int x){}
}
10) super keyword
Refers to parent class object.
[Link]();
11) static method, variable, block
Belongs to class, not object.
static int count;
static { count = 10; }
12) What is [Link]
System → class out → PrintStream println → method
[Link]("Hello");
13) What memory is cleared by GC
Only Heap memory is cleaned. Stack is auto‑cleared.
OBJECT ORIENTED PROGRAMMING
1) OOP features in Java
Encapsulation, Inheritance, Polymorphism, Abstraction
3
2) Composition vs Inheritance
Composition → HAS‑A (preferred) Inheritance → IS‑A
class Car { Engine e = new Engine(); }
3) Access specifiers
public, protected, default, private
4) Purpose of abstract class
Provide base with partial implementation.
abstract class Shape { abstract void draw(); }
5) Constructor vs Method
Constructor initializes object. Method defines behavior.
6) Diamond problem & solution
Java avoids it using interfaces.
interface A{ default void show(){} }
7) Local vs Instance variables
Local → inside method Instance → inside class
int x; // instance
void m(){ int y; }
4
8) Marker Interface
No methods, used by JVM (Serializable, Cloneable)
class A implements Serializable {}
DATA STRUCTURES & COLLECTIONS
1) Why String is immutable
Security, caching, thread‑safe
String s = "java";
[Link]("8");
2) String using new vs literal
Literal → String Pool new → Heap
String a = "hi";
String b = new String("hi");
3) Collection Framework
Unified architecture to store objects. (List, Set, Map)
4) ArrayList vs LinkedList
ArrayList → fast access LinkedList → fast insert/delete
5) HashMap vs TreeMap
HashMap → unordered TreeMap → sorted
5
6) HashSet vs TreeSet
HashSet → no order TreeSet → sorted
7) Iterator vs ListIterator
Iterator → forward ListIterator → bidirectional
8) Comparable interface
Defines natural ordering.
class A implements Comparable<A>{
public int compareTo(A o){ return 0; }
}
9) [Link]
Supports multithreading safely. (Executor, ConcurrentHashMap)
EXCEPTION HANDLING
1) What is an exception
Runtime abnormal condition.
2) Exception propagation
Unchecked exceptions move up call stack.
3) Checked vs Unchecked
Checked → compile‑time Unchecked → runtime
4) try‑catch
Handles runtime errors.
6
try{} catch(Exception e){}
5) throw vs throws
throw → explicitly throw throws → declare
6) finally block
Always executes.
7) Base class of exceptions
Throwable
8) Java SE vs Java EE
SE → core EE → enterprise (Servlets, JSP)
9) Servlet vs JSP
Servlet → Java code JSP → HTML + Java
✅ This content is fully interview‑ready. If you want: • Mock interview follow‑ups • PDF / DOC version •
1‑page quick revision sheet • Advanced Java interview questions
Tell me 👍