Interview Preparation Questions
Core Java & Object-Oriented Programming
● final keyword: Explain the usage of the final keyword for variables, methods, and
classes.
● String Concepts: What are the two ways to create a String? What is the difference
between them? Given the code String a = "Tata"; String b = a; a = "Birla";, what is the
final value of b and why?
● Method Overloading vs. Overriding: Explain the difference between method
overloading and method overriding.
● Pass by Value or Reference: Does Java work as "Pass by Value" or "Pass by
Reference"? Justify your answer.
● Inheritance & Polymorphism:
○ Explain the difference between an abstract class and an interface.
○ Explain the use of default methods in interfaces.
● Immutability: What is Java immutability? Explain how to design an immutable class.
How can you ensure a List field within an immutable class cannot be mutated from the
outside?
● Exception Handling: Explain the use of the finally block and "try-with-resources."
● Cloning: Explain the difference between deep cloning and shallow cloning.
Advanced Java & Frameworks
Java Versions & Features
● Java 8+ Features: What new features were introduced in Java versions after Java 8?
● Functional Interfaces: What is a functional interface? Is the @FunctionalInterface
annotation mandatory?
● Stream API:
○ Explain the Stream API, including the difference between intermediate and
terminal operations.
○ What is the difference between a Stream and a Parallel Stream? Explain the
internal working of a Parallel Stream.
○ When should you choose a regular Stream over a Parallel Stream?
● map() vs. flatMap(): What is the difference between the map() and flatMap() methods?
● Optional class: What is the purpose of the Optional class?
● Virtual Threads: What are virtual threads, and how are they used in Java?
Multithreading & Concurrency
● Deadlock: What is a deadlock, and how can you avoid it?
● Future vs. CompletableFuture:
○ How is CompletableFuture different from the Future object?
○ Be prepared to write service layer code using CompletableFuture and
demonstrate how to handle exceptions.
● Garbage Collection:
○ What are some garbage collector methods?
○ Can you manually call the garbage collector?
Object-Oriented Programming (OOP)
● Abstract Class vs. Interface:
○ Explain the difference between an abstract class and an interface.
○ When should you choose to use an interface versus an abstract class?
● finally vs. finalize(): What is the difference between the finally block and the finalize()
method?
Collections
● Sorted Maps: How can you maintain the keys of a Map in sorted order in Java?
Coding Questions (Java 8 Streams)
● Write a Java 8 program to find the sum of even numbers from a list of integers.
● Write code using streams to print the employee who works in the "Product Team" and is
located in "Bangalore".
● Multithreading & Concurrency:
○ What are the different ways to create a thread? What is the best approach?
○ Explain the volatile keyword.
○ What is an ExecutorService? Name some types of thread pools.
○ Explain the difference between CountDownLatch and CyclicBarrier.
○ What is a ConcurrentModificationException?
○ Explain CompletableFuture and the Future object.
○ Explain the Double-Checked Locking pattern and why a null check is important
before a synchronized block.
● Collections & Hashing:
○ Explain the internal working of a HashMap, including how it achieves O(1)
complexity, and scenarios where it degrades to O(n).
○ Explain the contract between the equals() and hashCode() methods. What
happens if you override only equals()?
○ Explain the difference between Comparable and Comparator.
○ Explain the internal workings of LinkedHashMap and ConcurrentHashMap.
● Database & Design Patterns:
○ What is a database connection pool? What are its advantages?
○ How would you implement a connection pool class as a Singleton?
● Testing: How do you test a method that throws an exception and assert its message
using JUnit 5's assertThrows()?
●
Multithreading & Concurrency
● How did you use threads in your project? (Interviewer expects CompletableFuture).
● What is the difference between Future and CompletableFuture?
● What is ExecutorService?
● What are the types of ExecutorService (e.g., Single thread, Fixed thread pool,
Scheduled)?
● Coding:
○ Implement a fixed thread pool with 2 threads and print outputs.
○ How do you make tasks run alternately between threads?
● What is inter-thread communication?
● Explain the use of wait(), notify(), and notifyAll().
● What are locks? Explain types of locks like ReentrantLock and ReadWriteLock.
● Explain the purpose of the .join() method. Why does further code wait for a thread to
execute after .join() when multithreading is for parallel processing?
● What is your experience with synchronization and thread management?
● How do you handle a scenario where an API call fails and needs to be rolled back in a
distributed system (e.g., using @transactional and its propagation levels)?
Design Patterns
● General Concepts:
○ What is a design pattern, and why do we use them in software projects?
○ Be prepared for scenario-based questions where you have to identify and justify
which design pattern to use. For example: "If you need to implement a method
public List<Flight> sortFlightsByCriteria(String criteria) where criteria can be 'time'
or 'distance', what approach would you take?" (Expected answer: Strategy
Pattern).
○ Be ready to provide a use case from your own experience where you have
employed a specific design pattern.
● Common Design Patterns:
○ Singleton:
■ Explain the Singleton design pattern.
■ What is the "double-checked locking" pattern in the context of Singleton?
(This can be a tricky question).
■ How would you solve the problem if a Singleton object returns another
object and a user modifies that returned object? (This assesses your
understanding of immutability and defensive copying).
○ Factory vs. Abstract Factory:
■ Explain the difference between the Factory and Abstract Factory patterns.
■ What are the disadvantages of the Factory pattern compared to the
Abstract Factory pattern?
○ Dependency Injection: Which design pattern would you use to inject
dependencies without using a framework like Spring?
○ Other common patterns to know: Builder, Adapter, Proxy, Delegate.
Object-Oriented Programming (OOP) & Core Principles
● Core OOP Concepts: Explain the core principles of OOP (Encapsulation, Inheritance,
Polymorphism, Abstraction).
● SOLID Principles: What are the SOLID design principles?
● Immutability:
○ What is immutability?
○ How do you make a class immutable?
● Cloning: What is the Cloneable interface? Explain the difference between a shallow
copy and a deep copy.
● Method Overloading vs. Overriding:
○ Explain the difference between method overloading and method overriding.
○ Can a static method be overloaded? Why or why not?
● Abstract Class vs. Interface:
○ Explain the difference between an abstract class and an interface.
○ Can a class be declared as abstract even if it has no abstract methods or
variables? If so, what is its use case?
● Access Modifiers: What are the different access modifiers in Java?
● Constructors: Can a constructor be private? If yes, what are its use cases?
● Inheritance: In the context of inheritance, is the following possible: Class B extends A {};
B objB = new A();? Explain why.
Collections & Data Structures
● What is the difference between HashSet and LinkedHashSet?
● Explain the internal working of a HashMap, including concepts like buckets, collisions,
load factor, and treeification.
● What is the difference between fail-fast and fail-safe iterators?
● Explain the internal working of ArrayList.
● Explain the internal working of LinkedList.
● Explain the contract between the equals() and hashCode() methods.
● Can a custom object (e.g., an Employee object) be used as a key in a HashMap? If so,
what are the requirements?
Hashing & Maps
● Explain how a HashMap achieves O(1) time complexity for get() and put() operations.
● In what scenarios does the time complexity of HashMap operations degrade to O(n)?
How did Java 8 address this issue?
● What is the loadFactor in a HashMap and what is its purpose?
● Explain the internal working of a LinkedHashMap. What is a practical use case for it,
such as an LRU Cache?
● Explain the internal implementation of a ConcurrentHashMap.
● What is the difference between a Synchronized HashMap and a ConcurrentHashMap?
○
Databases (SQL & NoSQL)
Databases: SQL & NoSQL
● SQL & NoSQL Differences: What are the key differences between SQL and NoSQL
databases? Can a relational schema be stored in a NoSQL database?
● Indexing: What is indexing, and what are its different types (e.g., Primary Index)?
● Joins:
○ Explain the difference between an INNER JOIN and an OUTER JOIN.
○ What is a LEFT OUTER JOIN?
○ What is a SELF JOIN? Provide a use case.
● SQL Queries:
○ Write a query to return the employee's name and department's name from two
tables (Employee and Department).
○ Write a query to return the employee's name and department's name, including
employees who have not yet been assigned to a department.
○ Find the 2nd and 3rd highest salary from an Employee table.
○ Find the employee with the maximum salary in each department.
○ Find the employee who is working on more than one project.
○ Find all employees who have a birthday in the current month.
○ Return the department name, max, min, and average salary for each department.
○ Write a query to find the department with more than 3 employees.
○ How can you calculate the average salary of employees grouped by their
department while also filtering out departments with less than five employees?
● Aggregate Functions: What are aggregate functions (SUM, MAX, COUNT, AVG)?
● ER Diagram: What is an ER (Entity-Relationship) diagram?
JPA & ORM
● JPA & Hibernate Relationship: Explain the relationship between JPA and Hibernate.
● JPA Relationships:
○ Explain the @OneToOne, @OneToMany, @ManyToOne, and @ManyToMany
JPA relationships.
○ How would you implement a @OneToMany relationship in JPA?
● Composite Keys:
○ What is a composite key?
○ How do you use a composite key in JPA?
Concurrency
● Synchronized Maps: When using a synchronized map, which object is locked?
● Database Isolation Levels: Discuss the different database isolation levels, explaining
the scenarios in which each one should be used.
● .
Microservices & Monoliths
● Microservices vs. Monoliths:
○ What are the key differences between a microservices architecture and a
monolithic architecture?
○ Provide practical examples of when to choose a microservices approach versus
a monolithic one.
● Database in Microservices: Is having a shared database among microservices a good
or workable practice? Justify your answer.
Scalability & Performance
● Scaling:
○ How do you scale a database?
○ How do you scale a microservice?
● AWS & Cloud Infrastructure:
○ Explain how AWS Auto Scaling works. Be prepared for scenario-based
questions.
○ What are Elastic Load Balancers? Explain their use and working.
○ Can you explain the concepts of VPC (Virtual Private Cloud) and DNS in AWS?
What are their roles in cloud infrastructure?
○ What strategies would you use to test a third-party service located outside of a
VPC?
● Optimization:
○ How would you optimize a Java application's performance? (Hint: Caching,
Cron-Jobs/Scheduling).
● Troubleshooting: What would you do if a microservice becomes slow, and how would
you remediate it?
Spring & Spring Boot
● Framework Differences:
○ What is the difference between the Spring and Spring Boot frameworks?
○ When would you choose one over the other?
○ What are the disadvantages of Spring Boot?
● Spring Boot Internals:
○ Explain how Spring Boot's auto-configuration works.
○ What is the role of spring.factories and starter POMs?
○ Explain the difference between @ConditionalOnClass and @ConditionalOnBean.
○ Describe what happens when a Spring Boot application starts. What is the
default embedded server, and how does it handle web traffic?
● Dependency Injection (DI) & IoC Container:
○ Explain the IoC (Inversion of Control) container.
○ What is a Spring Bean, and what are the different bean scopes?
○ Explain how DI works with beans.
○ Compare Field Injection and Constructor Injection. Which is preferred, and why?
1
○ Explain the difference between @Autowired and @Qualifier.
● Configuration Management:
○ How do you handle multiple configurations for different environments (e.g., dev,
test, prod)?
○ Explain the role of the @Profile annotation.
○ What is a Spring Cloud Config Server and how is it used to centralize
configurations for microservices?
● Data Access:
○ How do you connect to a database in Spring Boot?
○ How can you return a result set from a query?
○ What is the difference between Spring Data JPA and Hibernate?
● Other Concepts:
○ What is AOP (Aspect-Oriented Programming) in Spring, and can you provide an
example?
○ Explain caching and its use.
○ What is the Bean lifecycle?
2
○ Explain the difference between @Component and @Configuration.
○ What happens if a Spring Boot application has two main classes?
○
● What is the purpose of the @Primary annotation in Spring Boot?
● What is the purpose of the @Qualifier annotation in Spring Boot?
● What is the difference between @Primary and @Qualifier?
● How do @Primary and @Qualifier work together in Spring Boot?
● How do you create a custom exception in Spring Boot?
● How do you handle exceptions globally in Spring Boot using @ControllerAdvice?
● How can you run methods asynchronously in Spring Boot? (Hint: @Async)
Microservices & REST APIs
● API Design & Principles:
○ Explain the different HTTP methods (verbs) and their purposes. What is the
difference between PUT and POST?
○ Explain the role of HTTP status/response codes.
○ What are the different approaches to API versioning?
○ How do you secure REST APIs (e.g., Basic Auth, JWT)?
○ What is the difference between OAuth and JWT?
○ Explain the mechanism for token exchange in token-based authentication and its
security considerations.
● API Implementation:
○ How does a controller accept a request in Spring Boot? (Explain the internal
working).
○ Explain the difference between @Controller and @RestController. What happens
if you use @Controller in a service layer class?
○ Why would you use ResponseEntity?
○ How do you use interceptors with RestTemplate?
● Microservices Design Patterns:
○ API Gateway: Explain what an API Gateway is and how it differs from a Load
Balancer.
○ Service Discovery: What is a Service Registry, and can you name some
implementations (e.g., Eureka)?
○ Inter-Service Communication: What is the Saga pattern? Why and when would
you use it? Provide an example. What are the advantages of using a Feign
Client?
○ Resilience Patterns: Explain the Circuit Breaker pattern. How would you
implement it using a library like Resilience4j or Hystrix? Explain the concept of a
fallback method.
○ Centralized Logging & Tracing: How would you implement a centralized
logging mechanism (e.g., using the ELK Stack)? How do you use Spring Cloud
Sleuth and Zipkin?
● End-to-End Flow: Be prepared to design an end-to-end REST API flow, from the
controller to the database, including exception handling. For example, design an order
placement microservice.
● Exception Handling:
○ How do you handle exceptions in a Spring Boot application?
○ What is the difference between a checked and an unchecked exception?
● Cloud & Messaging:
○ What is your experience with AWS messaging services like SQS and SNS? How
did you implement them?
○ Explain the concept of a fallback method for a service that is down.
Other Concepts
● TLS vs. mTLS: What are the key differences between TLS and mTLS, and when would
you use each?
Apache Kafka
● Core Concepts:
○ What are the main features of Kafka?
○ Explain the overall working flow of Kafka, including the roles of Producers and
Consumers.
○ Explain the concept of a Consumer Group. How do rebalancing and the
Consumer Group Coordinator work?
○ Explain the roles of partitions and offsets.
○ What is the purpose of Zookeeper in a Kafka cluster?
● Kafka in Practice:
○ How have you integrated Kafka into your projects?
○ Describe a use case for Kafka in your current project.
○ What configurations do you use in your Kafka setup?
○ What is the daily message load on your Kafka system?
● Performance & Reliability:
○ What makes Kafka so fast?
○ How do you handle failure points and errors in a Kafka-based system?
● Data Ordering: If a producer is sending messages (A, B, C, D) where A and C belong to
one category and B and D to another, how can you ensure that when consuming, A is
always read before C, and B is always read before D?
Messaging & Event-Driven Systems
● General Concepts:
○ Have you worked with messaging or event-driven solutions?
○ Explain your understanding of Pub/Sub systems and message brokers.
● Kafka vs. Other Brokers:
○ What is the difference between Kafka and ActiveMQ?
○ Explain the use cases for RabbitMQ versus Kafka.
○ Given a scenario, such as processing a 500KB file, which message queue would
you choose and why (Kafka or ActiveMQ)?
Performance & JVM
● Explain Garbage Collection (e.g., Young Gen, Old Gen, algorithms like Mark & Sweep).
● What is JVM configuration for GC?
● Have you used any JVM profilers?
● What is your experience with performance tuning and optimization in Java applications?
Other Tools & Technologies
● What JSON handling libraries do you know (e.g., Jackson, Gson)?
● Do you have exposure to frontend technologies (JavaScript, Angular, React)?
● Which unit testing frameworks have you used (JUnit, Mockito)?
● Are you familiar with Java 11+ features (var, local-variable syntax, new APIs)?
● What are the key features of JDK 17 and JDK 21?
● How would you migrate a project from JDK 8 to JDK 17?
● What is SonarQube?
● How do you handle security in your project?
● Explain what a JWT (JSON Web Token) is and how you validate a token.
● Have you used Azure?
● Do you have experience with distributed caching like Redis?
Solution Design & Architecture
● Are you able to create high-level and low-level design documents?
● What is your experience with architecture principles and decision-making?
● Do you understand Non-Functional Requirements (security, compliance)?
● Are you familiar with gRPC, Service Mesh, and Polyglot systems?
● Explain how to handle communication between microservices.
● How do you test your application in the development environment?
Production Support & DevOps
● Do you have experience in bug fixing, release management, and troubleshooting?
● What is your knowledge of CI/CD pipelines, Docker, Kubernetes, and Cloud
provisioning?
● What monitoring and log management tools have you used?
● Do you have proficiency in log analysis and managing alerts across layers?
● How do you build your application?
● How do you deploy your application?
General Questions
● Are you serving a notice period?
● Are you open to learning full-stack development?
● Explain a challenging project you've faced.
● What is the difference between Spring and Spring Boot?
● Explain memory management in Java.
● Scenario-based discussion on asynchronous calls and API latency.
Coding:
String and Array Manipulation
● Anagrams: Write a program to find if two strings are anagrams of each other.
● Longest Uniform Substring: Given a string, find the longest uniform substring.
● First Non-Repeating Character: Write a function that finds the first non-repeating
character in a string.
● Merge Two Sorted Arrays: Merge two sorted arrays into a single sorted array without
using built-in sort functionalities.
● Find Top Two Elements: Write a code to find the max 2 elements from an array,
ensuring they are not the same in case of duplicates.
● Print Non-Duplicate Elements: Print the non-duplicate elements from a list.
● Integer Digits: Write a code to print an integer value like 4367 in a format like
4,3,6,7.
● Longest Unique Substring: Given a string (e.g., anczabc), find the longest substring
without repeating characters. (Output: ancz).
● Rock Collector's Road Trip: Given a grid of numbers, find the optimal path from a
starting point to an endpoint to accumulate the most rocks. You can only travel up or
right.
● Stock Buy/Sell Profit: Given a price array, find the maximum profit.
● Maximum Profit with Budget: Write a Java program to find the max profit based on a
given budget and a list of stock prices.
● Sorting a Map: Write a program to print a HashMap in sorted order of its keys.
Java 8 & Streams
● Functional Interface & Lambda: Write a functional interface and implement it with a
Lambda expression.
● Longest String with Streams: Given a string array, print the longest string using Java 8
streams.
● Most Frequent Number (with adjacency removal): Find the most occurring number in
a list and remove the adjacent of that number using streams only.
Multithreading & Concurrency
● Fixed Thread Pool: Implement a fixed thread pool with 2 threads and print outputs.
● Alternate Task Execution: How do you make tasks run alternately between threads?
● Inter-thread Communication: Write a code example demonstrating the use of wait(),
notify(), and notifyAll() for inter-thread communication.
Data Structures & Algorithms
● BFS (Breadth-First Search): Implement a shortestPath(from, to) method to find
the shortest path between two stations on a train map. Explain why BFS is the
appropriate approach.
● DFS (Depth-First Search): Implement a simple DFS traversal.
● Binary Search: Implement a function to find the first and last positions of a given
element in a sorted array.
● Binary Tree Traversals: Implement In-Order, Pre-Order, and Post-Order traversals of a
Binary Tree.
● Trapping Rain Water: Implement a solution to the "Trapping Rain Water" problem.
● Daily Temperatures: Implement a solution to the "Daily Temperatures" problem.
● Heap / Priority Queue:
○ Implement a min-heap without using PriorityQueue.
○ Explain the tree structure of a heap.