Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save carefree-ladka/b84ea8c4076fab8d186dbded65f52569 to your computer and use it in GitHub Desktop.

Select an option

Save carefree-ladka/b84ea8c4076fab8d186dbded65f52569 to your computer and use it in GitHub Desktop.
Complete Backend Java Interview Questions Guide

Complete Interview Questions Guide

A comprehensive collection of interview questions for Java, Spring Boot, SQL, System Design, and Low-Level Design


Table of Contents

10. SQL


Core Java

1.1 Object-Oriented Programming (OOP) Fundamentals

Core OOP Concepts

  1. What is OOP? Explain the four pillars

    • Encapsulation
    • Inheritance
    • Polymorphism
    • Abstraction
  2. What is encapsulation? How do you achieve it in Java?

  3. Explain inheritance with real-world example

  4. What is polymorphism? Types of polymorphism

    • Compile-time (Method Overloading)
    • Runtime (Method Overriding)
  5. What is abstraction? How is it different from encapsulation?

Classes & Interfaces

  1. Difference between abstract class vs interface (🔥 VERY common)
  2. When to use abstract class vs interface?
  3. Can an interface have:
    • default methods? (Java 8+)
    • static methods? (Java 8+)
    • private methods? (Java 9+)
    • instance variables?
  4. Can a class extend multiple classes?
  5. Can a class implement multiple interfaces?
  6. What is marker interface? Examples
  7. What is functional interface? (🔥 Java 8+)

Method Concepts

  1. What is method overloading?
  2. What is method overriding?
  3. Difference between overloading vs overriding
  4. Can we overload main() method?
  5. Can we override main() method?
  6. Can we override static methods?
  7. Can we override private methods?
  8. Can we override final methods?
  9. What is method hiding?
  10. What is covariant return type?

Modifiers & Keywords

  1. Explain access modifiers (public, private, protected, default)
  2. What is final keyword?
    • final variable
    • final method
    • final class
  3. What is static keyword?
    • static variable
    • static method
    • static block
  4. What is this keyword?
  5. What is super keyword?
  6. Difference between this vs super

Object Class & Core Methods

  1. Why Object class is parent of all classes?
  2. What is equals() method? (🔥 VERY common)
  3. What is hashCode() method? (🔥 VERY common)
  4. What is the contract between equals() and hashCode()? (🔥 Critical)
  5. Difference between == and equals()
  6. What is toString() method?
  7. What is clone() method? Deep vs shallow copy
  8. What is finalize() method? Is it deprecated?

1.2 String Handling

  1. Why is String immutable in Java? (🔥 VERY common)
  2. Benefits of String immutability
  3. What is String pool / String intern pool?
  4. Difference between String, StringBuilder, StringBuffer
  5. When to use StringBuilder vs StringBuffer?
  6. Can we make String mutable?
  7. What is String.intern() method?
  8. How many objects created: String s = new String("hello")?
  9. Difference between String s = "hello" vs String s = new String("hello")

1.3 Wrapper Classes & Autoboxing

  1. What are wrapper classes?
  2. Why do we need wrapper classes?
  3. What is autoboxing and unboxing?
  4. Performance impact of autoboxing
  5. What is Integer cache?
  6. Difference between Integer.valueOf() vs new Integer()

1.4 Memory Management & JVM

JVM Architecture

  1. Explain JVM architecture (🔥 Important)
  2. Difference between JDK vs JRE vs JVM
  3. What is ClassLoader?
  4. Types of ClassLoaders
  5. What is class loading process?
  6. What happens during class loading?
  7. What is static block execution order?

Memory Areas

  1. What is heap memory?
  2. What is stack memory?
  3. Difference between heap vs stack (🔥 VERY common)
  4. What is PermGen? Why was it removed?
  5. What is Metaspace? (Java 8+)
  6. What is Method Area?
  7. What is String Constant Pool?

Garbage Collection

  1. How does Garbage Collection work? (🔥 Important)
  2. What is minor GC vs major GC?
  3. What is full GC?
  4. What is Stop-the-World GC?
  5. Types of Garbage Collectors
    • Serial GC
    • Parallel GC
    • CMS (Concurrent Mark Sweep)
    • G1 GC
    • ZGC, Shenandoah
  6. How to make an object eligible for GC?
  7. Can we force garbage collection?
  8. What is memory leak in Java?

Memory Errors & Performance

  1. What is OutOfMemoryError?
  2. Types of OutOfMemoryError
  3. What is StackOverflowError?
  4. Difference between OutOfMemoryError vs MemoryLeakError
  5. How to detect memory leaks?
  6. JVM tuning parameters (-Xms, -Xmx)

Reference Types

  1. Strong reference
  2. Weak reference
  3. Soft reference
  4. Phantom reference
  5. When to use WeakHashMap?

1.5 Immutability & Design

  1. What is immutable class?
  2. How to create an immutable class? (🔥 Common)
  3. Benefits of immutability
  4. Is String immutable? Why?
  5. Can we make a class with mutable fields immutable?
  6. What is defensive copying?
  7. Examples of immutable classes in Java

Collections Framework

2.1 Core Interfaces

  1. What is Collections Framework?
  2. Core interfaces in Collections Framework
  3. Difference between Collection vs Collections
  4. What is Iterable interface?
  5. What is Iterator interface?
  6. What is ListIterator?
  7. Difference between Iterator vs ListIterator

2.2 List Interface

ArrayList

  1. What is ArrayList?
  2. How does ArrayList work internally?
  3. Initial capacity of ArrayList
  4. How ArrayList grows dynamically?
  5. When to use ArrayList?

LinkedList

  1. What is LinkedList?
  2. How does LinkedList work internally?
  3. Difference between ArrayList vs LinkedList (🔥 VERY common)
  4. When to use LinkedList vs ArrayList?

Vector & Stack

  1. What is Vector?
  2. Difference between ArrayList vs Vector
  3. Is Vector thread-safe?
  4. What is Stack class?

Array vs List

  1. Difference between Array vs ArrayList (🔥 Common)
  2. Can we change array size after creation?
  3. How to convert Array to ArrayList?
  4. How to convert ArrayList to Array?

2.3 Set Interface

HashSet

  1. What is HashSet?
  2. How does HashSet work internally? (🔥 Important)
  3. How HashSet prevents duplicates?
  4. Can HashSet have null values?
  5. Is HashSet ordered?

LinkedHashSet

  1. What is LinkedHashSet?
  2. Difference between HashSet vs LinkedHashSet
  3. How LinkedHashSet maintains insertion order?

TreeSet

  1. What is TreeSet?
  2. How does TreeSet work internally?
  3. Difference between HashSet vs TreeSet
  4. What is NavigableSet?
  5. Can TreeSet have null values?

2.4 Map Interface

HashMap

  1. What is HashMap?
  2. How does HashMap work internally? (🔥 EXTREMELY common - Must know)
  3. What happens on hash collision? (🔥 Critical)
  4. Why HashMap size is always power of 2? (🔥 Important)
  5. What is load factor in HashMap? (Default: 0.75)
  6. What is threshold in HashMap?
  7. When does HashMap rehash?
  8. What changed in HashMap after Java 8? (🔥 Important - Treeify)
  9. What is treeification in HashMap?
  10. When does HashMap convert linked list to tree?
  11. Can we use null key in HashMap?
  12. Can we use null values in HashMap?
  13. How many null keys allowed in HashMap?
  14. Time complexity of HashMap operations

Hashtable

  1. What is Hashtable?
  2. Difference between HashMap vs Hashtable (🔥 Common)
  3. Is Hashtable thread-safe?
  4. Can Hashtable have null key/values?
  5. Why Hashtable is legacy?

LinkedHashMap

  1. What is LinkedHashMap?
  2. How does LinkedHashMap maintain order?
  3. Difference between HashMap vs LinkedHashMap
  4. What is access order in LinkedHashMap?
  5. How to implement LRU cache using LinkedHashMap?

TreeMap

  1. What is TreeMap?
  2. How does TreeMap work internally? (Red-Black Tree)
  3. Difference between HashMap vs TreeMap
  4. Can TreeMap have null keys?
  5. What is NavigableMap?

ConcurrentHashMap

  1. What is ConcurrentHashMap? (🔥 VERY important)
  2. How does ConcurrentHashMap work internally? (🔥 Critical)
  3. Difference between HashMap vs ConcurrentHashMap
  4. How ConcurrentHashMap achieves thread-safety?
  5. What is segment locking? (Java 7)
  6. What changed in ConcurrentHashMap in Java 8?
  7. ConcurrentHashMap vs Hashtable vs Collections.synchronizedMap()

WeakHashMap

  1. What is WeakHashMap?
  2. When to use WeakHashMap?
  3. Difference between HashMap vs WeakHashMap

2.5 Queue Interface

  1. What is Queue interface?
  2. Difference between Queue vs Deque
  3. What is PriorityQueue?
  4. How does PriorityQueue work?
  5. What is ArrayDeque?
  6. LinkedList vs ArrayDeque

2.6 Fail-Fast & Fail-Safe Iterators

  1. What is fail-fast iterator? (🔥 Important)
  2. What is fail-safe iterator?
  3. Difference between fail-fast vs fail-safe
  4. Why does ConcurrentModificationException occur? (🔥 Common)
  5. How to avoid ConcurrentModificationException?
  6. Which collections are fail-fast?
  7. Which collections are fail-safe?
  8. Can we modify collection while iterating?

2.7 Comparable & Comparator

  1. What is Comparable interface?
  2. What is Comparator interface?
  3. Difference between Comparable vs Comparator (🔥 Common)
  4. When to use Comparable vs Comparator?
  5. Can we have multiple Comparators?
  6. How to sort custom objects?

2.8 Collections Utility Class

  1. What is Collections class?
  2. Collections.sort() - how it works?
  3. Collections.synchronizedList() vs CopyOnWriteArrayList
  4. Collections.unmodifiableList() - use case
  5. How to create thread-safe collections?
  6. Difference between synchronized collection vs concurrent collection

Multithreading & Concurrency

3.1 Thread Fundamentals

Thread Basics

  1. What is a thread?
  2. What is multithreading?
  3. Benefits of multithreading
  4. Difference between process vs thread
  5. What is main thread in Java?
  6. Thread lifecycle / states (🔥 Important)
    • NEW
    • RUNNABLE
    • BLOCKED
    • WAITING
    • TIMED_WAITING
    • TERMINATED

Creating Threads

  1. How to create a thread in Java?
  2. Difference between Thread class vs Runnable interface (🔥 Common)
  3. Which is better: extending Thread vs implementing Runnable?
  4. What is Callable interface? (🔥 Java 5+)
  5. Difference between Runnable vs Callable (🔥 Important)
  6. What is Future? (🔥 Important)
  7. What is FutureTask?
  8. What is CompletableFuture? (🔥 Java 8+)
  9. Difference between Future vs CompletableFuture

Thread Methods

  1. What is start() method?
  2. What is run() method?
  3. Difference between start() vs run() (🔥 Common)
  4. Can we start a thread twice? (🔥 Tricky)
  5. What happens if we call run() directly? (🔥 Tricky)
  6. What is sleep() method?
  7. What is join() method?
  8. What is yield() method?
  9. Difference between sleep() vs wait()
  10. What is interrupt() method?
  11. How to stop a thread?

3.2 Synchronization

Synchronized Keyword

  1. What is thread safety? (🔥 Important)
  2. What is race condition?
  3. What is synchronized keyword? (🔥 VERY important)
  4. Types of synchronization
    • Method level
    • Block level
    • Static synchronization
  5. Difference between synchronized method vs synchronized block
  6. What is object-level lock vs class-level lock?
  7. Can two threads execute two different synchronized methods?
  8. What is reentrant synchronization?

Wait, Notify, NotifyAll

  1. What is wait() method?
  2. What is notify() method?
  3. What is notifyAll() method?
  4. Why wait(), notify() in Object class not Thread? (🔥 Tricky)
  5. Difference between notify() vs notifyAll()
  6. Can we call wait() without synchronization?
  7. What is spurious wakeup?

Volatile Keyword

  1. What is volatile keyword? (🔥 Important)
  2. When to use volatile?
  3. Difference between synchronized vs volatile
  4. Can volatile guarantee atomicity?
  5. What is happens-before relationship? (🔥 Important)

3.3 Locks & Advanced Concurrency

ReentrantLock

  1. What is Lock interface?
  2. What is ReentrantLock? (🔥 Important)
  3. Difference between synchronized vs ReentrantLock (🔥 Common)
  4. What is fairness policy in locks?
  5. What is tryLock()?
  6. What is lockInterruptibly()?
  7. Benefits of ReentrantLock over synchronized

ReadWriteLock

  1. What is ReadWriteLock? (🔥 Important)
  2. When to use ReadWriteLock?
  3. Difference between ReentrantLock vs ReadWriteLock

Other Synchronizers

  1. What is Semaphore? (🔥 Important)
  2. Use cases of Semaphore
  3. What is CountDownLatch? (🔥 Important)
  4. What is CyclicBarrier? (🔥 Important)
  5. Difference between CountDownLatch vs CyclicBarrier (🔥 Common)
  6. What is Phaser? (Java 7+)
  7. What is Exchanger?

3.4 Executor Framework

  1. What is ExecutorService? (🔥 VERY important)
  2. What is Executor interface?
  3. What is Executors utility class?
  4. Types of thread pools
    • FixedThreadPool
    • CachedThreadPool
    • SingleThreadExecutor
    • ScheduledThreadPool
  5. Difference between FixedThreadPool vs CachedThreadPool (🔥 Common)
  6. What is ThreadPoolExecutor? (🔥 Important)
  7. How does ThreadPoolExecutor work internally?
  8. ThreadPoolExecutor parameters
    • corePoolSize
    • maximumPoolSize
    • keepAliveTime
    • workQueue
    • threadFactory
    • rejectedExecutionHandler
  9. What are rejection policies?
  10. What is ScheduledExecutorService?
  11. How to shutdown ExecutorService?
  12. Difference between shutdown() vs shutdownNow()

3.5 Concurrent Collections

  1. What are concurrent collections?
  2. ConcurrentHashMap (🔥 Covered in Collections)
  3. CopyOnWriteArrayList (🔥 Important)
  4. CopyOnWriteArraySet
  5. ConcurrentLinkedQueue
  6. BlockingQueue interface (🔥 Important)
  7. Types of BlockingQueue
    • ArrayBlockingQueue
    • LinkedBlockingQueue
    • PriorityBlockingQueue
    • SynchronousQueue
    • DelayQueue
  8. When to use BlockingQueue?

3.6 Threading Problems

  1. What is deadlock? (🔥 VERY important)
  2. How to prevent deadlock? (🔥 Important)
  3. How to detect deadlock?
  4. What is livelock?
  5. What is starvation?
  6. Difference between deadlock vs livelock vs starvation (🔥 Common)

3.7 Practical Concurrency Problems

  1. Implement Producer-Consumer problem (🔥 VERY common)
  2. Print even/odd using two threads (🔥 Common)
  3. Print sequence using three threads (🔥 Common)
  4. Implement thread-safe Singleton (🔥 Important)
  5. Implement blocking queue
  6. Implement read-write lock

Exception Handling

4.1 Exception Basics

  1. What is an exception?
  2. Exception hierarchy in Java
  3. Difference between Error vs Exception (🔥 Common)
  4. What is Throwable class?
  5. Can we catch Error? (🔥 Tricky)
  6. Should we catch Error?

4.2 Types of Exceptions

  1. Checked vs Unchecked exceptions (🔥 VERY common)
  2. Examples of checked exceptions
  3. Examples of unchecked exceptions
  4. What is RuntimeException?
  5. When to use checked vs unchecked exceptions?

4.3 Exception Handling Keywords

  1. What is try block?
  2. What is catch block?
  3. What is finally block? (🔥 Important)
  4. Will finally block always execute? (🔥 Common)
  5. When finally block won't execute?
  6. What is try-with-resources? (🔥 Java 7+)
  7. What is AutoCloseable interface?
  8. Can we have try without catch?
  9. Can we have multiple catch blocks?
  10. Catch block ordering rules

4.4 Throw vs Throws

  1. What is throw keyword?
  2. What is throws keyword?
  3. Difference between throw vs throws (🔥 Common)
  4. Can we throw checked exception without throws?
  5. Can we throw multiple exceptions?

4.5 Custom Exceptions

  1. How to create custom exception?
  2. When to create custom exceptions?
  3. Should custom exception be checked or unchecked?

4.6 Exception Handling in Methods

  1. Can a constructor throw exception? (🔥 Common)
  2. Can we override method and throw broader exception? (🔥 Tricky)
  3. Exception handling in method overriding
  4. What happens if exception occurs in finally? (🔥 Tricky)
  5. What happens if exception in catch block?

4.7 Best Practices

  1. Should we catch Exception or specific exceptions?
  2. Should we catch Throwable?
  3. When to use checked exceptions?
  4. When to use unchecked exceptions?
  5. Exception handling anti-patterns

Java 8+ Features

5.1 Lambda Expressions

  1. What is lambda expression? (🔥 VERY important)
  2. Syntax of lambda expression
  3. Benefits of lambda expressions
  4. What is functional interface? (🔥 Important)
  5. @FunctionalInterface annotation
  6. Can functional interface have multiple methods?
  7. Built-in functional interfaces
    • Predicate
    • Function
    • Consumer
    • Supplier
    • BiFunction, BiConsumer, BiPredicate
  8. What is method reference? (🔥 Important)
  9. Types of method references
  10. What is constructor reference?

5.2 Stream API

Stream Basics

  1. What is Stream API? (🔥 VERY important)
  2. Benefits of Stream API
  3. Difference between Collection vs Stream
  4. How to create streams?
  5. What is stream pipeline?

Stream Operations

  1. Intermediate vs Terminal operations (🔥 Important)
  2. What is lazy evaluation in streams? (🔥 Important)
  3. List of intermediate operations
    • filter()
    • map()
    • flatMap()
    • distinct()
    • sorted()
    • peek()
    • limit()
    • skip()
  4. List of terminal operations
    • forEach()
    • collect()
    • reduce()
    • count()
    • anyMatch(), allMatch(), noneMatch()
    • findFirst(), findAny()
    • min(), max()

Advanced Stream Concepts

  1. What is map() operation?
  2. What is flatMap() operation?
  3. Difference between map() vs flatMap() (🔥 VERY common)
  4. What is filter() operation?
  5. What is reduce() operation?
  6. What is collect() operation?
  7. What are Collectors?
  8. Common Collectors methods
    • toList(), toSet(), toMap()
    • joining()
    • groupingBy()
    • partitioningBy()
    • counting(), summingInt()

Parallel Streams

  1. What is parallel stream? (🔥 Important)
  2. How parallel streams work? (🔥 Important)
  3. When to use parallel streams?
  4. When NOT to use parallel streams? (🔥 Important)
  5. Performance considerations of parallel streams

5.3 Optional

  1. What is Optional? (🔥 VERY important)
  2. Why Optional was introduced?
  3. How to create Optional objects?
    • Optional.of()
    • Optional.ofNullable()
    • Optional.empty()
  4. Optional methods
    • isPresent()
    • ifPresent()
    • orElse()
    • orElseGet()
    • orElseThrow()
    • get()
  5. Why Optional should not be used as field? (🔥 Important)
  6. Optional best practices
  7. Optional anti-patterns

5.4 Date-Time API

  1. Why new Date-Time API was introduced? (Java 8)
  2. Problems with java.util.Date
  3. What is LocalDate?
  4. What is LocalTime?
  5. What is LocalDateTime?
  6. Difference between LocalDate vs Date (🔥 Common)
  7. What is ZonedDateTime?
  8. What is ZoneId?
  9. What is Instant?
  10. What is Period vs Duration?
  11. How to parse and format dates?
  12. What is DateTimeFormatter?

5.5 Interface Enhancements

  1. What are default methods in interface? (🔥 Java 8)
  2. Why default methods were introduced?
  3. Can interface have static methods? (🔥 Java 8)
  4. Can interface have private methods? (Java 9)
  5. Diamond problem with default methods

5.6 Other Java 8+ Features

  1. What is forEach() method?
  2. What is StringJoiner?
  3. Base64 encoding/decoding
  4. Nashorn JavaScript engine (Deprecated in Java 11)

Tricky & Conceptual Questions

6.1 Class & Object Concepts

  1. Can we have multiple public classes in a file? (🔥 Tricky)
  2. Can we execute Java program without main method? (Pre Java 7)
  3. Can main() method be overloaded? (🔥 Tricky)
  4. Can we make main() method final, static, synchronized?
  5. Why is main() method static? (🔥 Tricky)
  6. Can we declare class as static? (Only nested classes)
  7. What is static import?
  8. Can we override static method? (No, method hiding)
  9. Can constructor be static, final, synchronized, abstract?

6.2 Threading Tricky Questions

  1. Why wait() is in Object class not Thread? (🔥 VERY tricky)
  2. Can we start a thread twice? (🔥 Tricky)
  3. What happens if run() is called directly? (🔥 Tricky)
  4. Can we call start() method twice on same thread?
  5. What if both start() and run() are synchronized?

6.3 String & Performance

  1. Why StringBuilder is faster than StringBuffer? (🔥 Common)
  2. String vs StringBuilder vs StringBuffer - performance
  3. How many objects: String s1 = new String("hello");? (2 objects)
  4. What is String.intern() and when to use?

6.4 Collections Tricky Questions

  1. What happens if hashCode changes after insertion in HashMap? (🔥 VERY tricky)
  2. Can we make HashMap thread-safe? (Yes, multiple ways)
  3. How to synchronize HashMap?
  4. Can we store null in TreeMap? (No for key)
  5. Can we store null in TreeSet? (No)
  6. What happens if we put duplicate key in HashMap?

6.5 Inheritance & Polymorphism Tricky

  1. Can we inherit from multiple classes? (No, Diamond Problem)
  2. Why multiple inheritance not supported in Java? (🔥 Common)
  3. Can interface extend multiple interfaces? (Yes)
  4. Can class implement two interfaces with same method signature?
  5. What is diamond problem with default methods?
  6. Can we reduce visibility of inherited method? (No)

6.6 Memory & GC Tricky

  1. What happens during class loading? (🔥 Important)
  2. Order of execution: static block, constructor, instance block
  3. Can we call System.gc()? (Yes, but not guaranteed)
  4. Does finalize() always execute? (No, deprecated)
  5. Memory leak scenarios in Java

6.7 Enum Tricky Questions

  1. How does enum provide singleton? (🔥 Important)
  2. Can enum implement interface? (Yes)
  3. Can enum extend class? (No)
  4. Can we create enum instance using new? (No)

6.8 Serialization

  1. What is Serialization?
  2. What is Serializable interface?
  3. What is serialVersionUID?
  4. What is transient keyword?
  5. Can we serialize static variables? (No)
  6. Difference between Serializable vs Externalizable

6.9 Cloning

  1. What is deep copy vs shallow copy? (🔥 Common)
  2. How to create deep copy?
  3. What is clone() method?
  4. Why Cloneable is marker interface?
  5. Problems with clone() method

6.10 Miscellaneous Tricky

  1. Difference between new String("hello") vs "hello"
  2. Can finally block prevent return? (Yes)
  3. Can we have try-finally without catch? (Yes)
  4. What is tight coupling vs loose coupling?
  5. What is composition vs aggregation?
  6. Difference between break vs continue vs return

Advanced Java Concepts

7.1 Reflection API

  1. What is Reflection?
  2. When to use Reflection?
  3. How to get Class object?
  4. How to invoke private method using Reflection?
  5. Performance impact of Reflection
  6. Reflection security concerns

7.2 Annotations

  1. What are annotations?
  2. Built-in annotations
    • @Override
    • @Deprecated
    • @SuppressWarnings
    • @FunctionalInterface
  3. How to create custom annotation?
  4. Retention policies (SOURCE, CLASS, RUNTIME)
  5. Target types (@Target)

7.3 Generics

  1. What are Generics? (🔥 Important)
  2. Benefits of Generics
  3. Type Erasure in Java
  4. What are bounded types?
  5. Difference between <?> vs <T>
  6. What is wildcard?
    • Unbounded wildcard <?>
    • Upper bounded <? extends T>
    • Lower bounded <? super T>
  7. PECS principle (Producer Extends, Consumer Super)
  8. Can we create generic array? (No)

7.4 Design Patterns in Java

  1. Singleton pattern (🔥 Thread-safe implementations)
  2. Factory pattern
  3. Builder pattern
  4. Prototype pattern
  5. Adapter pattern
  6. Decorator pattern
  7. Observer pattern
  8. Strategy pattern

Spring / Enterprise

8.1 Spring Core

  1. What is Spring Framework?
  2. What is Spring IoC? (🔥 Important)
  3. What is Dependency Injection? (🔥 Important)
  4. Types of Dependency Injection
    • Constructor Injection
    • Setter Injection
    • Field Injection
  5. Which DI type is recommended and why? (Constructor)

8.2 Bean Lifecycle & Scopes

  1. What is Spring Bean?
  2. Bean lifecycle in Spring (🔥 Important)
  3. Bean scopes
    • Singleton (default)
    • Prototype
    • Request
    • Session
    • Application
  4. Difference between Singleton vs Prototype (🔥 Common)
  5. InitializingBean and DisposableBean
  6. @PostConstruct and @PreDestroy

8.3 Spring AOP

  1. What is AOP? (🔥 Important)
  2. AOP terminologies
    • Aspect
    • Join Point
    • Advice
    • Pointcut
    • Weaving
  3. Types of Advice
    • Before
    • After
    • AfterReturning
    • AfterThrowing
    • Around
  4. Use cases of AOP

8.4 Spring Transactions

  1. What is @Transactional? (🔥 VERY important)
  2. Propagation types (🔥 Important)
    • REQUIRED (default)
    • REQUIRES_NEW
    • NESTED
    • MANDATORY
    • SUPPORTS
    • NOT_SUPPORTED
    • NEVER
  3. Isolation levels
    • DEFAULT
    • READ_UNCOMMITTED
    • READ_COMMITTED
    • REPEATABLE_READ
    • SERIALIZABLE
  4. What happens when @Transactional fails?
  5. Rollback rules in @Transactional

8.5 Spring vs Spring Boot

  1. Difference between Spring vs Spring Boot (🔥 Common)
  2. How does Spring Boot auto-configuration work? (🔥 Important)
  3. What problems Spring Boot solves?
  4. Spring Boot starter dependencies
  5. Embedded servers in Spring Boot

Design & Architecture

9.1 Design Problems

  1. Design a thread-safe cache (🔥 Important)
  2. How would you implement LRU cache? (🔥 VERY common)
  3. Design rate limiter (🔥 Important)
  4. Design connection pool
  5. Design blocking queue

9.2 Scalability Questions

  1. How do you handle concurrency at scale? (🔥 Important)
  2. How would you optimize high-throughput APIs?
  3. How does ConcurrentHashMap achieve scalability? (🔥 Important)
  4. Strategies for handling million requests
  5. Database connection pooling strategies

9.3 Best Practices

  1. SOLID principles
  2. DRY, KISS, YAGNI
  3. Code review best practices
  4. Exception handling best practices
  5. Logging best practices
  6. Testing best practices


Spring Boot

9.1 Spring Boot Core

  1. What is Spring Boot and why was it introduced?
  2. Difference between Spring vs Spring Boot
  3. What problems does Spring Boot solve?
  4. What is auto-configuration?
  5. How does Spring Boot auto-configuration work internally?
  6. What is @SpringBootApplication?
    • Explain @Configuration, @EnableAutoConfiguration, @ComponentScan
  7. What is starter dependency?
  8. What is embedded server? Why is it used?
  9. How does Spring Boot decide Tomcat vs Jetty vs Undertow?
  10. What happens when you run a Spring Boot application?

9.2 Configuration & Properties

  1. What is application.properties vs application.yml?
  2. How do you define custom properties?
  3. What is @ConfigurationProperties vs @Value?
  4. What is profile? (@Profile)
  5. How do Spring Boot profiles work internally?
  6. Property precedence order in Spring Boot
  7. How to override properties at runtime?
  8. What is externalized configuration?

9.3 Dependency Injection & Beans

  1. What is IoC?
  2. What is Dependency Injection?
  3. Difference between @Component, @Service, @Repository
  4. What is @Autowired? How does it work internally?
  5. Constructor vs Field vs Setter injection (which is best & why?)
  6. What is @Primary?
  7. What is @Qualifier?
  8. Bean lifecycle in Spring Boot
  9. What is @Lazy?
  10. What are bean scopes?

9.4 REST APIs & Controllers

  1. Difference between @Controller vs @RestController
  2. What is @RequestMapping?
  3. Difference between @GetMapping, @PostMapping
  4. What is @RequestBody?
  5. What is @RequestParam vs @PathVariable?
  6. How does Spring Boot convert JSON to Java object?
  7. What is Jackson?
  8. How do you handle validation?
  9. What is @Valid vs @Validated?

9.5 Exception Handling

  1. What is @ExceptionHandler?
  2. What is @ControllerAdvice?
  3. Global vs local exception handling
  4. How to return custom error response?
  5. How to handle validation errors?
  6. What is ResponseEntity?

9.6 Spring Data JPA

  1. What is Spring Data JPA?
  2. Difference between JPA vs Hibernate
  3. What is JpaRepository?
  4. Difference between CrudRepository, PagingAndSortingRepository, JpaRepository
  5. How does Spring Boot create repository implementations?
  6. What is Entity?
  7. What is Persistence Context?
  8. What is Lazy vs Eager loading?
  9. What is N+1 problem?
  10. How to solve N+1 problem?
  11. What is @Transactional?
  12. Propagation types in @Transactional
  13. Isolation levels
  14. What happens if exception occurs inside @Transactional?

9.7 Security

  1. What is Spring Security?
  2. How authentication works in Spring Security?
  3. What is SecurityFilterChain?
  4. Difference between authentication vs authorization
  5. What is JWT?
  6. How JWT works with Spring Boot?
  7. Stateless vs Stateful authentication
  8. What is CSRF?
  9. How to disable CSRF?
  10. What is OAuth2?
  11. Difference between OAuth2 vs JWT

9.8 Actuator & Monitoring

  1. What is Spring Boot Actuator?
  2. Important actuator endpoints
  3. Difference between /health, /info, /metrics
  4. How do you secure actuator endpoints?
  5. What is Micrometer?

9.9 Testing

  1. Difference between @SpringBootTest vs @WebMvcTest
  2. What is @MockBean?
  3. Unit test vs Integration test
  4. How to test REST APIs?
  5. What is TestContainers?
  6. How to test JPA repositories?

9.10 Performance & Production

  1. How to improve Spring Boot startup time?
  2. What is lazy initialization?
  3. What is connection pooling?
  4. HikariCP vs others
  5. How do you handle high traffic?
  6. How do you make Spring Boot scalable?
  7. How do you deploy Spring Boot app?
  8. What is fat jar vs thin jar?

9.11 Tricky / Advanced Spring Boot

  1. Why is Spring Boot faster than Spring?
  2. What happens if two beans have same name?
  3. How does Spring Boot detect components?
  4. What is circular dependency?
  5. How to resolve circular dependency?
  6. What is ApplicationContext?
  7. Difference between ApplicationContext vs BeanFactory
  8. How does Spring Boot handle concurrency?

SQL

10.1 SQL Basics

  1. What is SQL?
  2. Difference between SQL vs NoSQL
  3. What are DDL, DML, DCL, TCL?
  4. Difference between DELETE vs TRUNCATE vs DROP
  5. What is PRIMARY KEY?
  6. Difference between PRIMARY KEY vs UNIQUE
  7. What is FOREIGN KEY?
  8. What is NULL?
  9. What is DEFAULT constraint?
  10. What is CHECK constraint?

10.2 Queries & Filtering

  1. Difference between WHERE vs HAVING
  2. Difference between IN vs EXISTS
  3. Difference between BETWEEN vs >= <=
  4. What is LIKE?
  5. What is ORDER BY?
  6. What is GROUP BY?
  7. Can we use aggregate functions without GROUP BY?
  8. What is DISTINCT?
  9. What is LIMIT / OFFSET?
  10. How does NULL behave in comparisons?

10.3 Joins

  1. Types of joins:
    • INNER
    • LEFT
    • RIGHT
    • FULL
  2. Difference between INNER JOIN vs WHERE
  3. What is SELF JOIN?
  4. What is CROSS JOIN?
  5. What is JOIN vs SUBQUERY?
  6. What happens if join condition is missing?
  7. How to find records present in one table but not the other?

10.4 Subqueries & CTEs

  1. What is subquery?
  2. Types of subqueries
  3. What is correlated subquery?
  4. What is CTE (WITH clause)?
  5. Difference between CTE vs Subquery
  6. Recursive CTE – when do we use it?

10.5 Indexing

  1. What is an index?
  2. Types of indexes:
    • B-Tree
    • Hash
    • Composite
    • Unique
  3. How does index improve performance?
  4. When index is not used?
  5. Downsides of indexing
  6. What is covering index?
  7. Difference between clustered vs non-clustered index
  8. Can a table have multiple clustered indexes?
  9. How to find slow queries?

10.6 Normalization & Design

  1. What is normalization?
  2. 1NF, 2NF, 3NF
  3. What is denormalization?
  4. When do we denormalize?
  5. OLTP vs OLAP
  6. Fact table vs Dimension table
  7. Star vs Snowflake schema

10.7 Transactions & ACID

  1. What is a transaction?
  2. ACID properties
  3. What is COMMIT?
  4. What is ROLLBACK?
  5. What is SAVEPOINT?
  6. What is auto-commit?
  7. What is isolation level?

10.8 Isolation Levels & Locks

  1. READ UNCOMMITTED
  2. READ COMMITTED
  3. REPEATABLE READ
  4. SERIALIZABLE
  5. Dirty Read
  6. Non-repeatable Read
  7. Phantom Read
  8. What is locking?
  9. Row-level vs Table-level lock
  10. What is deadlock?
  11. How databases detect deadlock?

10.9 Window Functions

  1. What are window functions?
  2. Difference between GROUP BY vs WINDOW function
  3. What is ROW_NUMBER()?
  4. RANK() vs DENSE_RANK()
  5. What is PARTITION BY?
  6. What is OVER()?
  7. Running totals using SQL
  8. Find top N per group

10.10 Performance & Optimization

  1. How do you optimize a slow query?
  2. What is EXPLAIN / EXPLAIN ANALYZE?
  3. Difference between INDEX SCAN vs TABLE SCAN
  4. Why SELECT * is bad?
  5. How to avoid full table scan?
  6. What is query caching?
  7. How pagination works internally?
  8. OFFSET vs Cursor-based pagination

10.11 Real-World SQL Problems

  1. Find 2nd highest salary
  2. Find duplicate records
  3. Delete duplicates but keep one
  4. Find employees without manager
  5. Find consecutive login days
  6. Running total per user
  7. Top N salary per department
  8. Swap two columns
  9. Find missing IDs
  10. Update using join
  11. Count rows per category including zero
  12. Find max salary per department

10.12 Tricky SQL Questions

  1. Difference between COUNT(*) vs COUNT(column)
  2. What happens if GROUP BY column missing?
  3. Why NULL != NULL?
  4. UNION vs UNION ALL
  5. How EXISTS is faster than IN?
  6. Why indexes slow down INSERT?
  7. What happens when index is rebuilt?

System Design (HLD)

11.1 Core System Design Questions

  1. Design URL Shortener (TinyURL)
  2. Design Rate Limiter
  3. Design Distributed Cache (Redis-like)
  4. Design Notification System
  5. Design Chat Application (WhatsApp / Messenger)
  6. Design News Feed (Facebook / Twitter)
  7. Design File Storage System (Google Drive / Dropbox)
  8. Design Search Autocomplete
  9. Design Logging / Monitoring System
  10. Design Payment System

11.2 Storage & Data-Intensive Systems

  1. Design Key-Value Store
  2. Design Distributed Database
  3. Design Time-Series Database
  4. Design Event Sourcing System
  5. Design Leaderboard
  6. Design Recommendation System
  7. Design Analytics / Metrics System
  8. Design Search Engine
  9. Design Log Aggregation System
  10. Design Data Warehouse

11.3 Scalability & Reliability

  1. What is horizontal vs vertical scaling?
  2. How do you design for high availability?
  3. CAP theorem (with examples)
  4. Consistency models (Strong / Eventual)
  5. Sharding strategies
  6. Replication (Leader-Follower, Multi-Leader)
  7. Load balancing strategies
  8. Caching strategies (Write-through, Write-back)
  9. Cache eviction policies (LRU, LFU)
  10. Handling hot keys

11.4 Communication & Networking

  1. REST vs gRPC
  2. HTTP vs WebSockets vs SSE
  3. Long polling vs polling
  4. Message queues vs streams
  5. Kafka vs RabbitMQ
  6. Exactly-once vs At-least-once delivery
  7. Idempotency
  8. API versioning
  9. Circuit Breaker pattern
  10. Backpressure

11.5 Consistency, Transactions & Fault Tolerance

  1. Distributed transactions
  2. Two-Phase Commit (2PC)
  3. Saga pattern
  4. Eventual consistency
  5. Quorum reads/writes
  6. Clock synchronization (NTP, logical clocks)
  7. Leader election
  8. Failover strategies
  9. Retry strategies
  10. Handling partial failures

11.6 Security & Observability

  1. Authentication vs Authorization
  2. OAuth2 / JWT
  3. Rate limiting for APIs
  4. DDoS protection
  5. Encryption at rest vs in transit
  6. Secrets management
  7. Monitoring metrics (RED / USE)
  8. Logging vs tracing
  9. Distributed tracing
  10. Alerting strategies

Low-Level Design (LLD)

12.1 Core OOP & Design Questions

  1. Design LRU Cache
  2. Design Parking Lot
  3. Design Elevator System
  4. Design ATM
  5. Design Library Management System
  6. Design Movie Ticket Booking System
  7. Design Chess / Snake & Ladder
  8. Design File System
  9. Design Splitwise
  10. Design Car Rental System

12.2 Concurrency-Heavy LLD

  1. Design Thread-Safe Cache
  2. Design Rate Limiter (Token / Leaky Bucket)
  3. Design Task Scheduler
  4. Design Producer-Consumer System
  5. Design Connection Pool
  6. Design Logger
  7. Design Thread Pool
  8. Design Message Queue
  9. Design Circuit Breaker
  10. Design Retry Mechanism

12.3 Design Patterns

  1. Singleton (thread-safe)
  2. Factory vs Abstract Factory
  3. Builder pattern
  4. Strategy pattern
  5. Observer pattern
  6. Decorator pattern
  7. Adapter pattern
  8. Proxy pattern
  9. Chain of Responsibility
  10. Command pattern

12.4 SOLID & Clean Design

  1. What is SOLID?
  2. SRP with real example
  3. OCP violation examples
  4. LSP violation examples
  5. ISP vs fat interfaces
  6. DIP in real systems
  7. Composition vs Inheritance
  8. Favor immutability
  9. Designing for extensibility
  10. Designing for testability

Interview Preparation Strategy

Must Master for 90% Coverage

Java:

  • HashMap internals
  • equals & hashCode
  • Multithreading basics + locks
  • Java memory model
  • Java 8 streams
  • ConcurrentHashMap

Spring Boot:

  • Auto-configuration (internal flow)
  • Dependency Injection
  • Spring Data JPA + Transactions
  • Exception Handling
  • Security (JWT flow)

SQL:

  • Joins
  • Window functions
  • Index usage
  • Transactions
  • Optimization

System Design:

  • Requirement clarification
  • Trade-offs
  • Scalability thinking
  • Failure handling
  • API + data modeling

LLD:

  • Clean class design
  • SOLID principles
  • Thread safety
  • Extensibility
  • Correct use of patterns

This document covers the most frequently asked interview questions from top product companies including Amazon, Microsoft, Google, Uber, Flipkart, and various fintech companies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment