𝗪𝗶𝘀𝘀𝗲𝗻 (DSA | Java | SpringBoot | System Design | SQL)
🟢 Java Basics
1. Why is Java considered a platform-independent language?
2. Why is Java not a purely object-oriented language?
3. What is the difference between JDK, JRE, and JVM?
4. What is the role of JIT compiler in Java?
5. What is the difference between Heap and Stack memory in Java?
⸻
🟠 OOPs & Core Concepts
6. What are the four pillars of OOPs in Java?
7. What is the difference between a class and an object?
8. What is the difference between a constructor and a method?
9. Can the main method be overloaded in Java?
10. What is the difference between method overloading and method overriding?
⸻
🔵 Inheritance & Polymorphism
11. What is inheritance and how is it implemented in Java?
12. What is the use of the super keyword in Java?
13. What does the final keyword mean with variables, methods, and classes?
14. What is method hiding in Java (static methods) vs method overriding?
15. What is the difference between an abstract class and an interface?
⸻
🟡 Strings & Memory
16. Why are Strings immutable in Java?
17. What is the difference between String, StringBuffer, and StringBuilder?
18. What is a Singleton class and how do you implement it?
19. What are shallow copy and deep copy in Java?
20. How does Java handle pass-by-value vs pass-by-reference?
⸻
🔴 Exception Handling
21. What is the difference between Exception and Error in Java?
22. What are checked exceptions and unchecked exceptions?
23. What is the difference between throw and throws?
24. What is the difference between final, finally, and finalize()?
25. What is try-with-resources in Java?
⸻
🟣 Advanced (Memory, Threads, GC)
26. What is garbage collection in Java and how does it work?
27. How are objects made eligible for garbage collection?
28. What is a ClassLoader in Java?
29. What are the two ways to create a thread in Java?
30. What is synchronization in Java? Give an example.
🔹 1. Java OOPs Concepts
Class & Object, Inheritance – Parent-child hierarchy, Polymorphism – Overloading & Overriding, Abstraction – Hiding details (abstract class & interface), Encapsulation – Data hiding via private fields
🔹 2. Wrapper Classes & Packages
Convert primitives → objects: int → Integer, double → Double, etc.
Useful in collections (List<Integer>), autoboxing/unboxing
Organize classes and avoid name conflict
🔹 3. Exception Handling
Checked Exceptions – Compile-time (e.g., IOException)
Unchecked Exceptions – Runtime (e.g., NullPointerException)
🔹 4. Generics
Generics allow enable classes, interfaces, and methods to operate on objects of various types while providing compile-time type safety.
🔹 5. JDK, JRE, JVM
JDK = JRE + development tools
JRE = JVM + libraries
JVM = Java Virtual Machine – runs bytecode
JIT Compiler = Just-In-Time compiler – converts bytecode to native at runtime
🔹 6. POJO vs. POJI
Plain Old Java Object – simple class with fields, getters/setters
Plain Old Java Interface – interface with no special restrictions
🔹 7. Access Modifiers
private → Class only
default → Same package
protected → Same package + subclass
public → Everywhere
🔹 8. Variables & Data Types
🔹 9. Garbage Collection & Memory Management
Automatic in JVM
Uses Mark & Sweep algorithm
Memory: Stack (method calls), Heap (objects)
🔹 10. String vs StringBuilder vs StringBuffer
🔹 11. Java 8 Features
Lambda Exp, Functional Programming, Functional Interfaces, Method References, Stream API
🔹 12. Hashing (Internal Working)
Used in HashMap, HashSet
HashCode → Bucket → Equals check
Collision handling via LinkedList/Tree (Java 8+)
🔹 13. Java Collection Framework
List – Ordered, duplicates (ArrayList, LinkedList)
Set – No duplicates (HashSet, TreeSet)
Map – Key-value pairs (HashMap, TreeMap, LinkedHashMap)
Thread-safe variants: ConcurrentHashMap, Vector, Collections.synchronizedList()
Comparator vs Comparable
Comparable – for default sorting logic defined inside the class (e.g., sort students by ID). method - compareTo(Object o)
Comparator – for custom sorting logic defined outside the class (e.g., sort students by name or marks). method - compare(Object o1, Object o2)
🔹 14. Multithreading
Lifecycle: new, runnable, running, blocked, terminated
Key concepts: synchronized, wait(), notify(), ExecutorService
🔹 15. Synchronization:
Ensures only one thread accesses a critical section at a time
synchronized keyword: method/block level
Prevents race conditions
Locks vs. Synchronization
ReentrantLock gives more control (e.g., tryLock, fairness)
Prefer Lock over synchronized in complex scenarios
🔹 16. JDBC & DAO
🔹 17. Java I/O Streams
InputStream / OutputStream → For binary data (byte-based)
Reader / Writer → For character data (char-based)
🔹 18. Serialization & Deserialization
Convert object → byte stream and vice versa
Use transient to skip fields
✅ 𝗟𝗲𝗲𝘁𝗰𝗼𝗱𝗲 𝗛𝗮𝗿𝗱 : Median of Two Sorted Arrays
Started with the merge-based brute force, then walked through the optimized partition-based binary search - where we 𝗶𝗺𝗮𝗴𝗶𝗻𝗲 a 1-D array and find the median using left/right partition logic (without actually merging).
Use: 𝗝𝗮𝘃𝗮-only, 𝗿𝘂𝗻𝗻𝗮𝗯𝗹𝗲 𝗰𝗼𝗱𝗲 𝗲𝘅𝗽𝗲𝗰𝘁𝗲𝗱.
✅ 𝗦𝗶𝗻𝗴𝗹𝗲𝘁𝗼𝗻 𝗣𝗮𝘁𝘁𝗲𝗿𝗻:
→ Write thread-safe singleton
→ Break it using Reflection
→ Explain 𝗥𝗲𝗳𝗹𝗲𝗰𝘁𝗶𝗼𝗻
✅ 𝗠𝘂𝗹𝘁𝗶𝘁𝗵𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗦𝗰𝗲𝗻𝗮𝗿𝗶𝗼:
I was given two methods, one synchronized, one static synchronized - both with infinite loops and launched via separate threads.
I was asked whether this setup could cause a 𝗱𝗲𝗮𝗱𝗹𝗼𝗰𝗸, and why.
My answer: No deadlock in this case, since 𝗶𝗻𝘀𝘁𝗮𝗻𝗰𝗲 𝗮𝗻𝗱 𝗰𝗹𝗮𝘀𝘀 𝗹𝗼𝗰𝗸𝘀 are separate.
✅ 𝗦𝗽𝗿𝗶𝗻𝗴 𝗗𝗮𝘁𝗮 𝗝𝗣𝗔:
How to avoid code duplication when multiple entities share common fields?
→ I misinterpreted the question and started explaining DTOs/ObjectMapper but later realized it was about entity inheritance / @MappedSuperclass.
✅ 𝗦𝘆𝘀𝘁𝗲𝗺 𝗗𝗲𝘀𝗶𝗴𝗻:
Design a file system: Create entity hierarchy + method to get size of any entity.
✅ 𝗦𝗤𝗟:
Transpose a matrix of student names & subjects into pivoted format.
(HARD - 3-4 attempts,couldn't solve it properly but the interviewer appreciated my approach.)
✅ 𝗞𝗮𝗳𝗸𝗮:
Architecture, retention policy, producer-consumer flow, etc.
✅ Remove duplicates from a sorted array
01) Introduce yourself.
02) Tell me about your project.
03) Write a REST API (on paper) to get all employees.
04) What is JPA and Hibernate?
05) Write OneToMany and ManyToOne relation using Employee and Department (on paper).
06) What is Fetch in JPA?
07) What is Cascade in JPA?
08) What is a JWT Token?
09) How do you implement JWT Token?
10) What is @Transactional?
11) What is Propagation in transactions and its types?
✅ Round 1 – Scenario-Based Questions
12) Write a custom JPA query with arguments age and salary to fetch employees.
13) In the same transaction, if I update a value and save it in DB, is it possible to get the updated value in the very next line?
✅ Round 1 – Java Concepts & Programs
14) What are Streams in Java?
15) What is a Functional Interface?
16) Program: Find the 2nd max value without using streams.
17) Program: Find students whose marks are greater than 80 using streams.
18) Program: Find the max marks of a student using sorted() in streams.
19) Program: Find the max marks of a student using max() in streams.
✅ Round 2 – Microservices & Advanced Concepts
20) How do microservices communicate with each other?
21) Apart from RestTemplate, what are other ways for microservice communication?
22) Explain synchronous vs asynchronous communication.
23) How does RabbitMQ work?
24) What will you do if you find an issue in production? How will you troubleshoot?
25) What is the SLF4J framework and how do you use it?
26) What is a JWT Token?
27) Difference between authentication and authorization.
28) HTTP status codes for Forbidden and Unauthorized.
29) Which occurs first: Forbidden or Unauthorized?
💭 Key Takeaways:
✅ Strong knowledge of JPA, Hibernate, and transactional behavior is critical.
✅ Hands-on practice with JWT, security, and Spring Boot microservices really helps.
✅ Production-level troubleshooting, logging, and message brokers (like RabbitMQ) are often discussed.
✅ Java Streams and Functional Programming are must-practice areas.
• Candle problem (n = unburnt candles, k = burnt candles needed to make one new candle)
SQL Query: Hotel table → order records by rating DESC (rating ≥ 7)
🔹 Round 2: Technical Interview
DSA Problem: Remove duplicates from a sorted array → e.g. {1,2,2,3,3,4} → {1,2,3,4,null,null}
Core Java & OOPs: Encapsulation, Collections framework usage, HashMap internal working, Array vs ArrayList
Hashing: equals() & hashCode() contract with custom objects in HashSet
Multithreading: Synchronization & custom problem → Print numbers up to N using 3 threads in sequence
SQL: Group students by name, calculate total marks, and sort by total marks
🔹 Round 3: Client + HR Discussion
Introduction, Experience, Current & Expected CTC, Work location
Technical:
• Time complexity of HashMap.get()
• Check if LinkedList is palindrome
• WeakHashMap explanation
• equals() & hashCode() contract when using a class as a key in Map
• Project discussion
1. 𝐈𝐧𝐝𝐞𝐱𝐢𝐧𝐠: Speed up read queries by creating indexes on frequently accessed columns.
2. 𝐕𝐞𝐫𝐭𝐢𝐜𝐚𝐥 𝐒𝐜𝐚𝐥𝐢𝐧𝐠: Add more CPU, RAM, or storage to the database server to handle higher workloads.
3. 𝐂𝐚𝐜𝐡𝐢𝐧𝐠: Use in-memory stores like Redis to serve hot data faster and reduce DB load.
4. 𝐒𝐡𝐚𝐫𝐝𝐢𝐧𝐠: Split the database into smaller, independent shards and distribute them across servers for horizontal scaling.
5. 𝐑𝐞𝐩𝐥𝐢𝐜𝐚𝐭𝐢𝐨𝐧: Create multiple copies (replicas) of the database across different servers to balance read traffic and improve availability.
6. 𝐐𝐮𝐞𝐫𝐲 𝐎𝐩𝐭𝐢𝐦𝐢𝐳𝐚𝐭𝐢𝐨𝐧: Fine-tune SQL queries, eliminate expensive operations, and leverage indexes effectively to improve execution speed.
7. 𝐂𝐨𝐧𝐧𝐞𝐜𝐭𝐢𝐨𝐧 𝐏𝐨𝐨𝐥𝐢𝐧𝐠: Reduce the overhead of opening/closing database connections by reusing existing ones.
8. 𝐕𝐞𝐫𝐭𝐢𝐜𝐚𝐥 𝐏𝐚𝐫𝐭𝐢𝐭𝐢𝐨𝐧𝐢𝐧𝐠: Split large tables into smaller, more manageable partitions, each containing a subset of the columns from the original table.
9. 𝐃𝐞𝐧𝐨𝐫𝐦𝐚𝐥𝐢𝐳𝐚𝐭𝐢𝐨𝐧: Store data in a redundant but structured format to minimize complex joins and speed up read-heavy workloads.
10. 𝐌𝐚𝐭𝐞𝐫𝐢𝐚𝐥𝐢𝐳𝐞𝐝 𝐕𝐢𝐞𝐰𝐬: Pre-compute and store results of complex queries as separate tables to avoid expensive recalculation.
1️⃣ Explain SOLID principles in Java with examples.
2️⃣ How does HashSet internally work?
3️⃣ Difference between String, StringBuffer, and StringBuilder.
4️⃣ Explain immutability in Java. How to create an immutable class?
5️⃣ How does Java handle memory management and garbage collection?
♦️ Spring & Spring Boot
6️⃣ Difference between @Bean, @Component, and @Configuration.
7️⃣ How does Spring Boot auto-configuration work internally?
8️⃣ How do you implement pagination and sorting in Spring Data JPA?
9️⃣ Explain the difference between @RequestParam, @PathVariable, and @RequestBody.
🔟 How do you schedule tasks in Spring Boot (with @Scheduled)?
♦️ JPA / Hibernate
1️⃣1️⃣ What are entity states in Hibernate (transient, persistent, detached, removed)?
1️⃣2️⃣ How do you implement batch processing in Hibernate?
1️⃣3️⃣ Difference between Criteria API and JPQL.
1️⃣4️⃣ How does inheritance mapping work in JPA (single table, joined, table per class)?
1️⃣5️⃣ What is orphanRemoval in JPA and how does it work?
♦️ Microservices & Architecture
1️⃣6️⃣ Difference between synchronous and asynchronous communication in microservices.
1️⃣7️⃣ How do you secure inter-service communication in microservices?
1️⃣8️⃣ Explain distributed transactions and the Saga pattern.
1️⃣9️⃣ How do you handle API rate limiting in microservices?
2️⃣0️⃣ How do you implement centralized logging and monitoring in microservices?
♦️ Cloud & DevOps Basics
2️⃣1️⃣ Explain difference between AWS EC2 and Lambda (or Azure VM and Functions).
2️⃣2️⃣ How do you configure environment variables and secrets in Docker/Kubernetes?
2️⃣3️⃣ Difference between Infrastructure as Code tools (Terraform vs CloudFormation).
2️⃣4️⃣ How do you achieve zero-downtime deployment in your applications?
2️⃣5️⃣ Explain autoscaling policies in cloud platforms.
1. 🔄 Internal working of HashMap.
2. 📚 Difference between ArrayList and LinkedList.
3. ⚡ What is volatile in Java?
4. 🤔 Difference between == and equals().
5. 🗑️ Explain Garbage Collection in JVM.
6. 🔒 How does a synchronized block work?
7. 📞 What are Callable and Future in Java?
8. 📊 Difference between Comparable and Comparator.
🔹 2. Advanced Java
1. 🌱 What is the lifecycle of a Servlet?
2. ♻️ How does JDBC connection pooling work?
3. 🌐 Difference between REST and SOAP APIs.
4. 🔍 Explain Filters and Listeners in Java EE.
5. 💳 How do you handle transactions in JDBC?
6. 🍪 Explain session management in Servlets.
7. 📋 Difference between Statement, PreparedStatement, and CallableStatement.
8. 📁 What is JNDI (Java Naming and Directory Interface)?
🔹 3. Microservices (Spring Boot)
1. 🚪 Explain API Gateway and its role.
2. 🔎 What is Eureka Service Discovery?
3. ⚡ Explain Circuit Breaker pattern (Hystrix/Resilience4j).
4. 💬 How do you implement Inter-service communication (Feign vs RestTemplate vs WebClient)?
5. 🔐 How do you secure microservices (JWT, OAuth2)?
6. ⚙️ Explain Config Server and centralized configuration.
7. 📝 How do you handle distributed logging and tracing (Zipkin/Sleuth)?
8. 🔄 What are eventual consistency and the Saga Pattern?
🔹 4. System Design
1. ✂️ Design a URL shortener like Bitly.
2. 🛒 Design an e-commerce order management system.
3. 💬 How would you scale a chat application like WhatsApp?
4. 🔔 How do you design a Notification Service for millions of users?
5. 🏗️ Difference between Monolithic and Microservices architecture.
6. 🗄️ Explain Database Sharding and Replication.
7. ⏱️ How do you design a Rate Limiter?
8. 💾 Design a caching system (like Redis-based).
🔹 5. Coding (DSA)
1. 📝 Reverse a Linked List.
2. 🔍 Find the first non-repeating character in a string.
3. 🗃️ Implement LRU Cache.
4. 🔄 Detect a cycle in a graph.
5. 📈 Find the maximum subarray sum (Kadane’s Algorithm).
6. 🧬 Merge two sorted arrays.
7. ✔️ Check if a string is a valid palindrome (ignore spaces/special chars).
8. 🎯 Find the Kth largest element in an array.
1. What’s the difference between volatile, synchronized, and Atomic classes?
2. How does the Java Memory Model (JMM) ensure visibility and ordering across threads?
3. How does CompletableFuture differ from Future?
4. How do you create and process a custom annotation at runtime?
5. What’s the difference between checked exceptions, unchecked exceptions, and errors?
6. How does Garbage Collection work in Java 17+ (G1 GC, ZGC)?
7. What are memory leaks in Java, and how can you detect and fix them?
8. How does Optional help reduce NullPointerException?
🔹 𝐒𝐩𝐫𝐢𝐧𝐠 & 𝐒𝐩𝐫𝐢𝐧𝐠 𝐁𝐨𝐨𝐭
9. How do you enable caching in Spring Boot with @Cacheable and @CacheEvict?
10. What’s the difference between BeanFactory and ApplicationContext?
11. Can you explain the Spring Bean lifecycle with an example?
12. When should you use @Lazy and @DependsOn?
13. How does Spring Boot auto-configuration work internally?
14. What is the role of spring.factories in Spring Boot?
15. How do application.properties and application.yml differ?
16. How is transaction management implemented in Spring Boot (declarative vs programmatic)?
17. What are the different @Transactional propagation types?
🔹 𝐒𝐩𝐫𝐢𝐧𝐠 𝐃𝐚𝐭𝐚 𝐉𝐏𝐀
18. How does JpaRepository differ from CrudRepository?
19. How do you implement pagination and sorting in Spring Data JPA?
20. How do you write a custom query using @Query annotation?
🔹 𝐑𝐄𝐒𝐓 𝐀𝐏𝐈𝐬 & 𝐌𝐢𝐜𝐫𝐨𝐬𝐞𝐫𝐯𝐢𝐜𝐞𝐬
21. How do you handle exceptions in REST APIs with @ControllerAdvice and @ExceptionHandler?
22. What’s the difference between @RestController and @Controller?
23. How do you secure a REST API with Spring Security and JWT?
24. What are the key differences between Kafka producer and consumer configurations in Spring Boot?
25. How would you design an event-driven microservice architecture with Spring Boot, Kafka, and REST APIs?
• Reverse a String in Java without using built-in methods.
• Check if a string is a palindrome.
• Find duplicates in an array.
• Find missing number in an array containing numbers 1 to n.
• Find the factorial of a number (using recursion or iteration).
• Generate the Fibonacci series (iteratively and recursively).
• Swap two numbers without using a third variable.
• Print all permutations of a string (recursive and iterative).
• Find the largest and smallest elements in an array.
• Search for an element in a rotated sorted array in time.
• Sum of all numbers in an array (with/without streams or functional style).
• Reverse an array in place.
• Merge overlapping intervals (advanced, common for experienced roles).
• Find maximum subarray sum (Kadane’s Algorithm).
• Detect if a linked list has a cycle.
Advanced and Tricky Java Interview Tasks
• Create a thread-safe Singleton class (using Enum approach).
• Design a mini library management or banking system.
• Write a custom class loader.
• Implement a vending machine design with code.
• Circular array rotation with efficient queries.
• Return an MD5 hash of a string.
• Implement merge of two sorted arrays.
• Find all unique elements present in either of two arrays (merge names problem).
𝗛𝗮𝗻𝗱𝗹𝗲 𝗘𝗿𝗿𝗼𝗿𝘀 𝗟𝗶𝗸𝗲 𝗮 𝗣𝗿𝗼! 💡 💡
In real-world REST APIs, exceptions are inevitable. But writing try-catch blocks in every controller? Not clean. Luckily, Spring Boot gives us a smarter way to handle them globally!
𝗛𝗼𝘄 𝗶𝘁 𝘄𝗼𝗿𝗸𝘀 ?
Using @ControllerAdvice and @ExceptionHandler Annotations
@ControllerAdvice is a special annotation used to handle exceptions globally across all controllers in a Spring Boot application.
It acts like a centralized error handler, so you don’t need to write try-catch in every controller.
Here’s how to do it:
𝟭. 𝗖𝗿𝗲𝗮𝘁𝗲 𝗮 𝗖𝘂𝘀𝘁𝗼𝗺 𝗘𝘅𝗰𝗲𝗽𝘁𝗶𝗼𝗻
For domain-specific errors like ResourceNotFoundException.
𝟮. 𝗕𝘂𝗶𝗹𝗱 𝗮 𝗚𝗹𝗼𝗯𝗮𝗹 𝗘𝘅𝗰𝗲𝗽𝘁𝗶𝗼𝗻 𝗛𝗮𝗻𝗱𝗹𝗲𝗿
Use @ControllerAdvice to manage all application-wide exceptions in one place.
𝟯. 𝗧𝗵𝗿𝗼𝘄 𝗬𝗼𝘂𝗿 𝗖𝘂𝘀𝘁𝗼𝗺 𝗘𝘅𝗰𝗲𝗽𝘁𝗶𝗼𝗻
Use it wherever needed - no more repetitive error-handling logic.
𝟰. 𝗖𝗿𝗲𝗮𝘁𝗲 𝗮 𝗦𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗲𝗱 𝗘𝗿𝗿𝗼𝗿 𝗥𝗲𝘀𝗽𝗼𝗻𝘀𝗲
Define a consistent response format to improve client-side error handling.
You can also handle:
Validation errors → 𝗠𝗲𝘁𝗵𝗼𝗱𝗔𝗿𝗴𝘂𝗺𝗲𝗻𝘁𝗡𝗼𝘁𝗩𝗮𝗹𝗶𝗱𝗘𝘅𝗰𝗲𝗽𝘁𝗶𝗼𝗻
Unauthorized access → 𝗔𝗰𝗰𝗲𝘀𝘀𝗗𝗲𝗻𝗶𝗲𝗱𝗘𝘅𝗰𝗲𝗽𝘁𝗶𝗼𝗻
𝟭. 𝗖𝗼𝗿𝗲 𝗦𝗽𝗿𝗶𝗻𝗴 𝗕𝗼𝗼𝘁 𝗔𝗻𝗻𝗼𝘁𝗮𝘁𝗶𝗼𝗻𝘀
@SpringBootApplication - Combines @Configuration, @EnableAutoConfiguration, and @ComponentScan entry point for Spring Boot apps.
@ComponentScan - Tells Spring where to scan for components, services, and configs.
@EnableAutoConfiguration - Let's Spring Boot configure beans based on dependencies.
@Configuration - Marks a class as a source of bean definitions.
𝟮. 𝗦𝘁𝗲𝗿𝗲𝗼𝘁𝘆𝗽𝗲 𝗔𝗻𝗻𝗼𝘁𝗮𝘁𝗶𝗼𝗻𝘀 (𝗖𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁 𝗧𝘆𝗽𝗲𝘀)
@Component: A Generic bean managed by Spring.
@Service Marks a service class (business logic).
@Repository DAO layer - integrates with JPA exception translation.
@Controller MVC web controller.
@RestController - Combines @Controller + @ResponseBody for REST APIs.
𝟯. 𝗪𝗲𝗯 & 𝗥𝗘𝗦𝗧 𝗔𝗣𝗜 𝗔𝗻𝗻𝗼𝘁𝗮𝘁𝗶𝗼𝗻𝘀
@RequestMapping Maps HTTP requests to handler methods (GET, POST, etc.).
@GetMapping, @PostMapping, @PutMapping, @DeleteMapping, @PatchMapping Shorthand for specific HTTP methods.
@PathVariable - Binds a URI template variable to a method parameter.
@RequestParam - Binds query parameters to method arguments.
@RequestBody - Binds JSON/XML body to a Java object.
@ResponseBody - Sends method return value as HTTP response body.
@CrossOrigin - Enables CORS for APIs.
𝟰. 𝗗𝗲𝗽𝗲𝗻𝗱𝗲𝗻𝗰𝘆 𝗜𝗻𝗷𝗲𝗰𝘁𝗶𝗼𝗻 𝗔𝗻𝗻𝗼𝘁𝗮𝘁𝗶𝗼𝗻𝘀
@Autowired- Injects a bean automatically by type.
@Qualifier - Chooses between multiple beans of the same type.
@Value - Injects values from properties or environment.
@Primary Marks a bean as default if multiple exist.
𝟱. 𝗝𝗣𝗔 & 𝗗𝗮𝘁𝗮𝗯𝗮𝘀𝗲 𝗔𝗻𝗻𝗼𝘁𝗮𝘁𝗶𝗼𝗻𝘀
@Entity marks a class as a JPA entity.
@Table Maps entity to a specific database table.
@GeneratedValue specifies how the primary key is generated.
@Column - Maps a field to a DB column.
@JoinColumn specifies a foreign key column.
@Transactional Marks a method/class to run inside a transaction.
𝟲. 𝗩𝗮𝗹𝗶𝗱𝗮𝘁𝗶𝗼𝗻 𝗔𝗻𝗻𝗼𝘁𝗮𝘁𝗶𝗼𝗻𝘀
@Valid - Triggers validation before method execution.
@NotNull, @NotBlank, @NotEmpty Field must not be null/blank/empty.
@Size(min, max) Checks string/collection size.
@Email - Valid email format.
@Pattern - Regex validation.
𝟳. 𝗦𝗽𝗿𝗶𝗻𝗴 𝗕𝗼𝗼𝘁 𝗨𝘁𝗶𝗹𝗶𝘁𝘆 𝗔𝗻𝗻𝗼𝘁𝗮𝘁𝗶𝗼𝗻𝘀
@EnableScheduling - Enables scheduled tasks.
@Scheduled- Runs a method on a schedule.
@EnableCaching - Enables caching.
@Cacheable, @CachePut, @CacheEvict Caching operations.
@Profile - Enables beans for specific env (dev, prod).
@ConditionalOnProperty - bean only if a property is set.
𝟴. 𝗚𝗹𝗼𝗯𝗮𝗹 𝗘𝘅𝗰𝗲𝗽𝘁𝗶𝗼𝗻 𝗛𝗮𝗻𝗱𝗹𝗶𝗻𝗴
@ControllerAdvice handles exceptions, global data binding, and model attributes for controllers.
@RestControllerAdvice Same as @ControllerAdvice, but automatically returns JSON (@ResponseBody included).
@ExceptionHandler defines a method to handle specific exception types.
1. Explain equals() vs ==. How do you correctly override equals() and hashCode()?
2. Why is String immutable in Java? What are the benefits?
3. Difference between StringBuilder and StringBuffer. When would you use each?
4. Explain pass-by-value in Java. How does it work with objects?
5. How do static variables and methods behave in multi-threaded applications?
𝗖𝗼𝗹𝗹𝗲𝗰𝘁𝗶𝗼𝗻𝘀 & 𝗚𝗲𝗻𝗲𝗿𝗶𝗰𝘀 :
6. Difference between HashMap, LinkedHashMap, and ConcurrentHashMap.
7. Why are HashMap keys required to be immutable?
8. Explain fail-fast vs fail-safe iterators with examples.
9. How do generics work in Java? What is type erasure?
10. When would you prefer CopyOnWriteArrayList over ArrayList?
𝗖𝗼𝗻𝗰𝘂𝗿𝗿𝗲𝗻𝗰𝘆 & 𝗠𝘂𝗹𝘁𝗶𝘁𝗵𝗿𝗲𝗮𝗱𝗶𝗻𝗴 :
11. Difference between synchronized block and ReentrantLock.
12. How does volatile work internally? Can it make a compound operation atomic?
13. Difference between ExecutorService, ForkJoinPool, and parallel streams.
14. Explain CompletableFuture and how it improves async programming.
15. Deadlock, livelock, and starvation – explain with real-world examples.
𝗝𝗩𝗠 & 𝗣𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲 :
16. Explain JVM memory structure (Heap, Stack, Metaspace).
17. Difference between Minor GC and Major GC. What is Stop-the-World (STW)?
18. What are different garbage collectors in Java 11/17? (G1, ZGC, Shenandoah)
19. How do you troubleshoot a memory leak in production? Tools you’d use?
20. Explain class loading mechanism and different class loaders.
𝗔𝗱𝘃𝗮𝗻𝗰𝗲𝗱 𝗖𝗼𝗻𝗰𝗲𝗽𝘁𝘀 :
21. Difference between checked, unchecked, and error in exception hierarchy.
22. How does Optional help avoid NullPointerException? Any drawbacks?
23. How do you implement immutability in custom classes?
24. What is reflection? When is it used? Downsides?
25. How do annotations work internally in Java?
• Difference between HashMap, HashTable, and ConcurrentHashMap
• How does Garbage Collection work in JVM?
• Explain volatile and synchronized in multithreading
• Deep copy vs Shallow copy
• How does the Java memory model work (Heap, Stack, Metaspace)?
𝗦𝗽𝗿𝗶𝗻𝗴 & 𝗦𝗽𝗿𝗶𝗻𝗴 𝗕𝗼𝗼𝘁
• What is Dependency Injection? How does Spring handle it internally?
• Difference between @Component, @Service, and @Repository
• How does Spring Boot auto-configuration work?
• Exception handling best practices in REST APIs
• How to secure REST APIs (JWT, OAuth2)?
𝗝𝗣𝗔 / 𝗛𝗶𝗯𝗲𝗿𝗻𝗮𝘁𝗲
• Difference between Lazy and Eager loading
• What are N+1 query problems? How to solve them?
• How does Hibernate manage transactions?
• Entity lifecycle states (Transient, Persistent, Detached, Removed)
𝗦𝗤𝗟 & 𝗗𝗮𝘁𝗮𝗯𝗮𝘀𝗲
• Write a query to find the 2nd highest salary from Employee table
• Difference between INNER JOIN, LEFT JOIN, RIGHT JOIN
• What are indexes? Clustered vs Non-clustered
• How to optimize slow queries?
𝗗𝗦𝗔 / 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 𝗦𝗼𝗹𝘃𝗶𝗻𝗴
• Implement LRU Cache
• Detect a cycle in a linked list
• Find longest substring without repeating characters
• Merge overlapping intervals
• Design a rate limiter
𝗦𝘆𝘀𝘁𝗲𝗺 𝗗𝗲𝘀𝗶𝗴𝗻
• Design a URL Shortener like bit.ly
• How would you scale a notification service?
• Difference between Monolith vs Microservices
• Use of API Gateway and Load Balancer
• CAP Theorem explanation with real-world examples
1️⃣ What is an Object?
2️⃣ What is a Constructor?
3️⃣ What is Stream API?
4️⃣ What is flatMap?
5️⃣ What are Collections?
6️⃣ What are Object methods?
7️⃣ What is Method Overloading?
8️⃣ Can a Constructor be overridden?
9️⃣ What is StringBuilder?
🔟 What is Immutability?
1️⃣1️⃣ How do we create Immutable Objects?
1️⃣2️⃣ What is a Singleton?
1️⃣3️⃣ What is a Thread?
1️⃣4️⃣ What are the ways to create a Thread?
1️⃣5️⃣ What is a Set & how does it work internally?
📌 Spring Boot Question
1️⃣6️⃣ What are Spring Boot Actuators?
2. Explain the Bean lifecycle in Spring (with example).
3. What are @Lazy and @DependsOn annotations in Spring, and when to use them?
4. How does Spring Boot auto-configuration work internally?
5. What is the role of spring.factories in Spring Boot?
6. What is the difference between application․properties and application.yml in Spring Boot?
7. How do you implement transaction management in Spring Boot (declarative vs programmatic)?
8. Explain the difference between @Transactional propagation types in Spring.
9. What is the difference between JpaRepository and CrudRepository in Spring Data JPA?
10. How do you handle pagination and sorting in Spring Data JPA?
11. How to implement a custom query in Spring Data JPA using @Query annotation?
12. Explain how to implement exception handling in REST APIs using @ControllerAdvice and @ExceptionHandler.
13. What is the difference between @RestController and @Controller in Spring?
Comments
Post a Comment