Complete Java Interview Prep Sheet (Final Version)
1. Core OOP Concepts
4 Fundamental Principles:
- Abstraction: Hide implementation details, show only essential features (abstract classes/interfaces). (what to implement).
- Encapsulation: Bundle data + methods, hide internals using private fields + public getters/setters (data hiding).
- Inheritance: Child class acquires parent class properties (is-a relationship, single inheritance only).
- Polymorphism: Same interface, multiple forms (compile-time: method overloading; runtime: method overriding).
Key Points:
- Java not pure OOP (uses primitives, no multiple class inheritance).
Objectclass is root of all classes:equals(),hashCode(),toString(),wait()/notify().- Multiple inheritance via interfaces only (no diamond problem).
2. Java Basics
Class/Object/Method:
- Class = blueprint/template
- Object = runtime instance (
new ClassName()) - Method = block of code performing specific task
Variables:
- Local: method scope only
- Instance: per object (non-static)
- Static: class-level, shared by all objects
Data Types:
Primitives (8): byte, short, int, long, float, double, char, boolean
Reference: String, arrays, classes, interfaces, wrappers
Arrays: Fixed size, same type elements, objects themselves (int[] arr = new int[5];)
Packages: Organize classes (java.lang auto-imported, java.io for streams)
3. Wrapper Classes
Purpose: Convert primitives to objects for Collections, APIs
int β Integer | char β Character
long β Long | boolean β Boolean
float β Float | double β Double
Key Methods: Integer.parseInt("123"), Integer.valueOf(5)
Autoboxing: Integer i = 5; (Java 5+ auto conversion)
4. JVM/JDK/JRE
JDK = Development Kit (javac + JVM + tools)
JRE = Runtime Environment (JVM + libraries)
JVM = Executes bytecode (platform independence)
Flow: .java β javac β .class (bytecode) β java β Run anywhere
5. Exception Handling
| Type | Checked By Compiler? | Examples |
|---|---|---|
| Checked | Yes | IOException, SQLException |
| Unchecked | No | NullPointerException, ArrayIndexOutOfBoundsException |
| Error | No | OutOfMemoryError, StackOverflowError |
Syntax:
| |
Custom: class MyException extends Exception {}
6. Collections Framework
| Collection | Key Classes | When to Use |
|---|---|---|
| List | ArrayList, LinkedList | Ordered, duplicates OK |
| Set | HashSet, TreeSet, LinkedHashSet | No duplicates |
| Map | HashMap, TreeMap, ConcurrentHashMap | Key-value pairs |
| Queue | PriorityQueue, ArrayDeque | FIFO/priority |
Performance:
ArrayList: O(1) get, O(n) insert middle
LinkedList: O(1) insert/delete, O(n) get
HashMap: O(1) average get/put
TreeMap: O(log n) sorted operations
Critical: hashCode() + equals() contract MUST be consistent
7. Multithreading
Create Threads:
| |
Synchronization:
| |
wait()/notify(): Inter-thread communication (must be in synchronized block)
Modern (java.util.concurrent):
ExecutorService+ thread poolsCallable+Future(return values)ConcurrentHashMap,CopyOnWriteArrayList
8. Java 8+ Features
Lambdas: (params) -> expression
| |
Streams:
| |
Optional: Avoid NullPointerException
| |
9. Memory & Garbage Collection
Memory Areas:
Heap: Objects, instance variables
Stack: Method frames, local variables
GC: Automatic memory reclamation of unreachable objects
- Use
try-with-resourcesfor cleanup - Tune with JVM flags (
-Xmx,-Xms)
10. Spring Framework (Interview Essentials)
Core Concepts:
- IoC Container: Manages object lifecycle
- DI:
@Autowiredinjects dependencies
Annotations:
@Component, @Service, @Repository, @Controller
@RestController, @RequestMapping
@RequestParam, @PathVariable
Spring Boot:
@SpringBootApplicationapplication.properties- Auto-configuration
11. Hibernate/JPA
Core Annotations:
@Entity, @Table
@Id, @GeneratedValue
@OneToMany, @ManyToOne, @JoinColumn
Key Concepts:
- Lazy vs Eager loading
- Persistence Context
- Dirty Checking (auto updates)
- Caching (1st/2nd level)
Quick Review Checklist
β
OOP 4 pillars + Object class
β
Collections + hashCode contract
β
Exceptions hierarchy
β
Multithreading basics + sync
β
Java 8 lambdas/streams/Optional
β
JVM basics
β
Spring DI + annotations
β
Hibernate relationships
Print this sheet. 2 pages max. You’re ready for interviews.