0% found this document useful (0 votes)
4 views5 pages

Java SpringBoot Interview Explained Guide

The document provides a comprehensive guide on Java and Spring Boot interview topics, covering key concepts such as JVM, JDK, memory management, multithreading, SOLID principles, and design patterns. It also explains Spring Boot's startup flow, dependency injection, transaction management, and optimization techniques. Additionally, it introduces Kafka concepts and the Saga pattern for managing distributed transactions.

Uploaded by

akash gupta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Java SpringBoot Interview Explained Guide

The document provides a comprehensive guide on Java and Spring Boot interview topics, covering key concepts such as JVM, JDK, memory management, multithreading, SOLID principles, and design patterns. It also explains Spring Boot's startup flow, dependency injection, transaction management, and optimization techniques. Additionally, it introduces Kafka concepts and the Saga pattern for managing distributed transactions.

Uploaded by

akash gupta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java & Spring Boot Interview Explained

Guide

JVM vs JRE vs JDK

JDK is used for development and contains compiler, debugger and JVM.
JRE provides environment to run Java applications.
JVM executes Java bytecode and manages memory.

Flow:
.java → javac → .class → JVM execution

Heap vs Stack Memory

Stack Memory stores local variables and method calls. It is thread specific.
Heap Memory stores objects and is shared across threads.

Example:
User u = new User();
Reference variable is in stack while object is in heap.

equals vs == vs hashCode

== checks reference equality.


equals() checks logical/content equality.
hashCode() is used internally by hashing collections like HashMap.

If two objects are equal then their hashCode must also be equal.

HashMap Internal Working

HashMap stores data in buckets.


Key hashCode is calculated and converted into bucket index.
Collisions are handled using linked list and balanced tree (Java 8+).

Average complexity is O(1).

ConcurrentHashMap

ConcurrentHashMap is thread safe and allows concurrent read/write operations.


It uses bucket level locking instead of locking the entire map.
Better performance than Hashtable.

Multithreading Concepts

Multithreading allows multiple tasks to execute simultaneously.

Important concepts:
- Thread lifecycle
- Runnable vs Callable
- synchronized keyword
- ExecutorService
- CompletableFuture
- Deadlock and Race Condition

Thread Pool Execution

Thread pools manage reusable threads.

Important parameters:
- corePoolSize
- maxPoolSize
- BlockingQueue
- RejectedExecutionHandler

CPU bound tasks require smaller pools while IO bound tasks can use larger pools.

SOLID Principles

S - Single Responsibility Principle


O - Open Closed Principle
L - Liskov Substitution Principle
I - Interface Segregation Principle
D - Dependency Inversion Principle

Builder Pattern

Builder pattern helps create immutable and readable objects.


It is useful when objects contain many optional parameters.
Frequently used with Lombok @Builder.

Java Records

Java Records are immutable data carrier classes introduced to reduce boilerplate code.
They automatically generate constructor, getters, equals, hashCode and toString methods.
Spring Boot Startup Flow

Spring Boot starts by creating IOC container and ApplicationContext.


Component scanning happens and beans are created.
Auto configurations are loaded using [Link] / AutoConfiguration classes.

Dependency Injection

Dependency Injection means Spring injects dependencies automatically instead of developers creating objects
manually.

Types:
- Constructor Injection
- Setter Injection
- Field Injection

@Transactional

@Transactional manages database transactions.


If runtime exception occurs transaction rolls back by default.

Important propagation types:


- REQUIRED
- REQUIRES_NEW
- SUPPORTS

Lazy vs Eager Loading

Eager loading fetches related entities immediately.


Lazy loading fetches related entities only when needed.

Lazy loading improves performance in many cases.

N+1 Problem

N+1 problem occurs when one query loads parent data and additional queries load child data repeatedly.

Solutions:
- Fetch Join
- EntityGraph
- Batch fetching

Database Optimization Techniques


Important optimization techniques:
- Proper indexing
- Composite indexes
- Pagination
- Batch updates
- Connection pooling using HikariCP
- Read replicas and sharding

Load Balancing

Load balancing distributes traffic across multiple servers.

Algorithms:
- Round Robin
- Least Connections
- Sticky Sessions

Common tools:
- NGINX
- HAProxy

Kafka Concepts

Kafka is a distributed event streaming platform.

Core concepts:
- Producer
- Consumer
- Topic
- Partition
- Offset
- Consumer Group

Saga Pattern

Saga pattern manages distributed transactions in microservices.


Types:
- Choreography based
- Orchestration based

Used to maintain consistency without global locks.

Low Level Design Concepts

LLD focuses on class level design and object interaction.

Important topics:
- Interfaces and abstraction
- Composition over inheritance
- SOLID principles
- Design patterns
- UML and class relationships

Builder Pattern Example


public class User {
private final String name;
private final int age;

private User(Builder builder) {


[Link] = [Link];
[Link] = [Link];
}

public static class Builder {


private String name;
private int age;

public Builder setName(String name) {


[Link] = name;
return this;
}

public Builder setAge(int age) {


[Link] = age;
return this;
}

public User build() {


return new User(this);
}
}
}

Java Record Example


public record Employee(
int id,
String name,
String department
) {}

You might also like