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).
  • Object class 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

TypeChecked By Compiler?Examples
CheckedYesIOException, SQLException
UncheckedNoNullPointerException, ArrayIndexOutOfBoundsException
ErrorNoOutOfMemoryError, StackOverflowError

Syntax:

1
2
3
4
try { risky code }
catch (SpecificException e) { handle }
catch (Exception e) { general handle }
finally { cleanup always runs }

Custom: class MyException extends Exception {}


6. Collections Framework

CollectionKey ClassesWhen to Use
ListArrayList, LinkedListOrdered, duplicates OK
SetHashSet, TreeSet, LinkedHashSetNo duplicates
MapHashMap, TreeMap, ConcurrentHashMapKey-value pairs
QueuePriorityQueue, ArrayDequeFIFO/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:

1
2
3
4
5
6
// Way 1
class MyThread extends Thread { public void run() {} }

// Way 2 (preferred)
class MyRunnable implements Runnable { public void run() {} }
Thread t = new Thread(new MyRunnable());

Synchronization:

1
2
synchronized void method() {}  // method-level
synchronized(this) { }         // block-level

wait()/notify(): Inter-thread communication (must be in synchronized block)

Modern (java.util.concurrent):

  • ExecutorService + thread pools
  • Callable + Future (return values)
  • ConcurrentHashMap, CopyOnWriteArrayList

8. Java 8+ Features

Lambdas: (params) -> expression

1
2
list.forEach(x -> System.out.println(x));
Comparator.comparing(Person::getName)

Streams:

1
2
3
4
list.stream()
    .filter(x -> x > 10)
    .map(x -> x * 2)
    .collect(Collectors.toList())

Optional: Avoid NullPointerException

1
Optional.ofNullable(value).orElse("default")

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-resources for cleanup
  • Tune with JVM flags (-Xmx, -Xms)

10. Spring Framework (Interview Essentials)

Core Concepts:

  • IoC Container: Manages object lifecycle
  • DI: @Autowired injects dependencies

Annotations:

@Component, @Service, @Repository, @Controller
@RestController, @RequestMapping
@RequestParam, @PathVariable

Spring Boot:

  • @SpringBootApplication
  • application.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.