0% found this document useful (0 votes)
60 views19 pages

Springsaver

This document is a copyright notice and introduction to an ebook authored by Amitesh Kumar Ray, aimed at students and professionals preparing for Java developer interviews. It includes a comprehensive collection of over 500 commonly asked Java interview questions, covering various topics such as Spring Boot, Spring Security, Spring Data, and Java fundamentals. The author, a seasoned software engineer, emphasizes the importance of this resource for enhancing interview preparation and technical knowledge in Java development.

Uploaded by

sairajvelpula
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)
60 views19 pages

Springsaver

This document is a copyright notice and introduction to an ebook authored by Amitesh Kumar Ray, aimed at students and professionals preparing for Java developer interviews. It includes a comprehensive collection of over 500 commonly asked Java interview questions, covering various topics such as Spring Boot, Spring Security, Spring Data, and Java fundamentals. The author, a seasoned software engineer, emphasizes the importance of this resource for enhancing interview preparation and technical knowledge in Java development.

Uploaded by

sairajvelpula
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
You are on page 1/ 19

Copyright

Copyright © 2024 by AK Ray

All rights reserved.

This ebook is protected by copyright law. The content within is intended specifically for students and
working professionals to enhance their learning and professional growth. Unauthorized use of this
material for monetary gain, reproduction, distribution, or any other commercial purpose is strictly
prohibited. Any attempt to exploit this content in such a manner is a violation of copyright law and will be
subject to legal action.

For permission requests or inquiries, please contact:

Portfolio : https://www.amiteshkumar.in/
Topmate : https://topmate.io/amitesh_kumar_ray
LinkedIn : https://www.linkedin.com/in/amitesh-kumar-ray/

Disclaimer: The information provided in this ebook is for general informational purposes only and should
not be considered as professional, legal, or financial advice. The author and publisher disclaim any
liability or responsibility for any loss or damage incurred as a consequence of the use of the information
presented in this book.

First Edition
About the Author

Amitesh is a highly accomplished software engineer with over 11 years of experience in


core software development, specializing in product-based organizations across India and
abroad. He is currently a Lead Software Development Engineer (SDE) at M2P
Fintech.

Holding a certification in System Design and Architecture from the University of


Alberta, Amitesh is also pursuing an Advanced Certificate Program in Applied AI & ML
from IIT Madras, an intensive 11-month program.

His technical expertise spans Java, Spring Boot, Microservices, AWS, Kafka, Python,
AI, and Machine Learning, making him a sought-after mentor and industry expert.

A passionate contributor to the developer community, Amitesh has authored 15+ books
on Java, Spring Boot, and Microservices, empowering developers with in-depth
knowledge. With a keen focus on technical excellence, he has conducted over 500
technical interviews in the past 4-5 years, helping organizations identify top engineering
talent.

Through his books, mentorship, and professional engagements, Amitesh remains


dedicated to sharing his knowledge and expertise, shaping the future of software
development.

Warm regards,




Overview

In today's fast-changing tech world, Java remains a key pillar of software


development. As a Lead Engineer in a top product-based company, I have
conducted over 500 interviews and faced many myself. Based on these
experiences, I have compiled this comprehensive collection of 500+
commonly asked Java interview questions for developers with 0 to 15
years of experience.

Each question in this book has been carefully selected, reviewed, and
refined by industry experts to ensure relevance and depth. Whether you're
preparing for your first job or aiming for a senior position, this resource
will help you build confidence and excel in your interview journey.

These questions cover widely used Java concepts, making them an essential
practice tool for interview preparation. I hope this book becomes a valuable
companion as you advance in your Java development career.
​Who This Book Is For ?
This book is designed for any engineering student or working professional aspiring
to secure a Java developer role. Whether you're just starting your career or have up
to 15 years of experience, this book will serve as a valuable resource. It contains
some of the most commonly asked interview questions, providing you with the
insights and preparation you need to confidently tackle technical interviews at all
stages of your career.

If you're looking to sharpen your skills, improve your understanding of Java, and
stand out in job interviews, this book is a perfect fit for you.​
Springboot:
1.​ What are the most common annotations you have used in your application
2.​ How does the bean lifecycle work? Explain all
3.​ What is profile and how does it help
4.​ How to keep database creds in spring application
5.​ You have 4 environments for application ,how do you manage configurations for each
environment.
6.​ Why does the Rest API returns result in json only ? what if i want xml
7.​ What are the conditional annotations in spring and how does it help, tell me the use case
you have in your application.
8.​ How do you map your request data to entities while saving to DB ? What kind of mapper
are you using for it?
9.​ How do you handle exceptions in springboot ?
10.​How do you create your own exception ? and how do you handle global exception
handling ?
11.​How does autoconfiguration help developers ?
12.​What if I want to perform some acting right after the spring container is initialized ? How
do we do it ? and why it's needed ,tell me some use cases if you have done in your
application.
13.​What is @Qualifier and how does it help?
14.​Can you tell me how your request reaches your Rest Controller ?
15.​Tell me some spring cloud components that you have used in your application.
16.​How to achieve security using spring boot.
17.​How to secure data over the network
18.​Using stream api fetch emp record based on their department. <emp_dept, list<emp>>
19.​What is blackduck?
20.​Can we have a prototype bean inside a singleton bean in spring boot?
21.​Type of vulnerability faced in project
22.​Non functional required you will ask before start working on any project
23.​How do you handle exception in your Springboot app
24.​How to implement global exception handling in Springboot microservice?
25.​How to handle exceptions using AspectJ ? explain in detail
26.​How to enable distributed logging for your microservices? What are the tools you have
ever used?
Spring Security
27.​What is the best way to call an API from another service ? What are the steps you need
to take care of while you are integrating your service to external and internal services ?
Do you see any security steps you need to take care about ?
28.​How have you leveraged OAuth2 in your application ?
29.​How are you getting auth token from auth server and how does it get refreshed?
30.​Explain the grant type with the use cases that you have used in your application.
31.​How does the resource server verify your token ? does it hit the auth server all the time
for each request ? How can you optimize this behavior ?
32.​How to avoid users to use the most commonly used password in springboot ? Do you
see any library or any other option to do it ?
33.​Can you explain to me the Auth flow in springboot ? assume you are calling some API
then how your request will proceed and you get a response ?
34.​How springboot remember you if you call some APIs 2nd time ,does it do all auth steps
again ?
35.​How can you implement your own auth provider ?
36.​What auth server you are using and how you are validating users? What if I want my
resources to be protected ? How will you do it?
37.​Explain the difference between Authentication and Authorization in Spring
Security.
38.​What is the role of the UserDetailsService interface in Spring Security?
39.​How do you implement custom authentication in Spring Security?
40.​What is a SecurityContext, and how does it work in Spring Security?
41.​How do you secure a REST API using Spring Security?
42.​What are the differences between Role-based and Permission-based access
control in Spring Security?
43.​How does Spring Security support OAuth2 and OpenID Connect for authentication?
44.​Explain how to implement method-level security using @PreAuthorize and @Secured
annotations.
45.​What is the role of Spring Boot Actuator, and how can it be used for monitoring and
management in a microservices architecture?
46.​How do you configure security in a Spring Boot application without using Spring
Security's default configuration?
47.​Explain how Spring Boot integrates with external configuration sources, such as
databases or cloud configuration services.
48.​How does Spring Boot manage transactions, and what are the different propagation and
isolation levels you can configure?
49.​What are the benefits and challenges of using Spring Boot with a reactive stack (e.g.,
WebFlux) compared to traditional MVC?
50.​How do you implement and configure a custom filter or interceptor in a Spring Boot
application?
51.​Explain the purpose of Spring Boot @Conditional annotations and how you can create
custom conditions for auto-configuration.
52.​How do you document your Rest API ?
53.​How to handle input validation in spring ? What are the possible ways and which one is
the best?
54.​How do you document your Rest APIs ?
55.​How to enable security for Swagger docs ?
56.​What is JWT ?
57.​What is OAuth2.0 and how you have used it in your project.
58.​How you have handle security for service-to-service communication
59.​What are the Grant Types in OAuth2 , explain the use case for each grant type I should
go for.
60.​How are you handling Authentication and Authorization in your application ? what are
the Auth servers you have ever used in your application.
61.​What is OIDC and what does it do? Have you used it in your application ? If yes,tell me
the flow.
62.​What is LDAP and how can you integrate it with your Auth server?
63.​How are you securing your resources in your microservice architecture ? what are the
possible way to secure the resources in Springboot.
64.​What are the possible ways to keep a logged-in user logged-in ? How do you manage
the session for your Auth token ?
65.​How to avoid accepting the most commonly used password as password. For example i
don't want my application to accept Test@123 or Test123, abc1234 or any similar String
that are most widely used or very simple to guess
SpringData:

66.​How do you integrate your application with different databases ?


67.​How does the CrudRepository differ from the JpaRepository in Spring Data JPA?
68.​Can you tell me the hierarchy of classes and interfaces of Spring Data ? How can you
create your own Repository ?
69.​How do you write a query method in springboot ? Tell me some most widely used rules
while writing your query methods.
70.​How to run SQL query in springboot ? as we already have the option to write a query
method then why do we go for native SQL queries ?
71.​How do you handle pagination and sorting in Spring data MySQL and SpringData
mongo OR others.
72.​How do you handle auditing in Spring data JPA? And why do you need this ?
73.​How do you handle composite keys and primary keys in Entity class?
74.​Have you used Flyway ? How does it help us?
75.​How to tune your join query ?
76.​How to make your select query faster ? Tell me some techniques you have used in your
application.
77.​What is sharding and partitioning ? How does it help ?
78.​Have you ever used indexing ? If yes, tell me the use cases.
79.​Get the 3rd topper student from table using jpa
80.​Get the last five and first five results from the table.
81.​Group by employee name and get the highest salary employee from each group.
82.​How do you design DB for your services ? What if your database went down ?
83.​Why should I go for mongoDB ?
84.​Are you aware of any columnar database ? Why should we go for it ?
85.​What are the approaches to handle SQL exceptions in springboot? What are the best
practices I should follow if I am implementing CRUD apis ?
86.​How do you handle joins in spring data ?
87.​What is the best way to design your data access layer ?
88.​What kind of cache are you using ? Do you see any benefits of using cache ?
89.​How to customize connection pool behavior in latest version of springboot (3.3)
90.​How to add a composite key in springboot?
91.​How to write custom queries in spring boot based on field name , tell me some
examples.
92.​N+1 Problem in Hibernate
Java

93.​What is cloning and why do we go for it?


94.​What is serialization , why do we use it ? What is the use of serialVersionUID ?
95.​Can I keep an Employee object or any custom object as Hashmap Key ?
96.​Why do we keep hashmap keys as immutable ?
97.​How do we achieve immutability in java ? how to write your own immutable class ?
98.​Why do we use generics with collections objects ?
99.​Can you override the static method ?
100.​ How do you utilize overloading concepts while implementing apis ?
101.​ How do you handle exceptions in child class ?
102.​ What is method reference and variable inference in java ?
103.​ Can you create your own exception class ? How do you manage exception handling
in your application ?
104.​ Which version of java are you using in your application ? Tell me some common
features ?
105.​ What are the enhancements in java date time apis in java 8?
106.​ What is hashcode and equals contract and how do you use it in your application? Tell
me some use cases.
107.​ What is String and how does it differ from StringBuffer and StringBuilder ? Can you
tell me the use-cases where we should go for it?
108.​ What are the possible ways to create DTO/POJO in java ?
109.​ What is Record in java? Tell me your opinion on whether I should use Lombok
,Records and simple DTO with setter/setter. How you are doing it in your application.
110.​ What is the latest version of Java ? Tell me some features from it.
111.​ Which version of java do you like most and why ? Why do we say Java8 is the
baseline for a functional programming approach ?
112.​ Tell me features of java 8, how Lambda and Stream help us to write better and
simplified code.
113.​ What is the default method and why was it introduced ? Where to use this ? tell me
the use-cases.
114.​ What is Optional ? What does it do ? how it help to avoid NPE
115.​ What is variable inference? Can you tell me its benefits and drawbacks ?
116.​ What is Sealed classes/Interface in java and where to use it?
117.​ How do you handle exceptions in your application? Tell me some best practices for it.
118.​ What is OOPS and tell me about its concepts?
119.​ What is the IS-a and Has-a relationship ? how you have used it in your application.
Tell me some examples of it.
120.​ What is Abstraction ? Why do we go for it? Tell me some use-case where its required
and you have done the same in your application.
121.​ What is late binding and early binding ? Why do we go for it ? How do you handle
exceptions in case of overriding ?
122.​ What is a functional interface ? why its required and list some pre-defined function
interfaces in java.
123.​ What is generics and why is it required ? do you see any enhancements in the latest
java version, if yes ,please tell.
124.​ What is the contract between hashcode(..) and equals(..) method.
Collections API:
125.​ What are the design pattern you have recently used in your project
126.​ What is the Java Collections Framework, and what are its main interfaces?
127.​ Explain the difference between ArrayList and LinkedList. When would you use
one over the other?
128.​ How does a HashMap work? What are its key properties?
129.​ What are the differences between HashMap and TreeMap?
130.​ What is the significance of ConcurrentHashMap? How does it differ from
HashMap?
131.​ How does LinkedHashMap maintain insertion order? What are its advantages over
HashMap?
132.​ What is the difference between HashSet and TreeSet? When would you use
each?
133.​ How does PriorityQueue work, and what are its typical use cases?
134.​ Explain the concept of Hashtable. How does it differ from HashMap?
135.​ What is the role of the Collection interface in Java? How does it differ from List,
Set, and Queue?
136.​ How does the Iterator interface work? What is the difference between Iterator
and ListIterator?
137.​ What are Collections.synchronizedList,
Collections.synchronizedMap, and Collections.synchronizedSet used
for?
138.​ Describe how the List interface works and its common implementations.
139.​ How does the Set interface handle duplicate elements? What are its common
implementations?
140.​ What is the difference between ArrayList and Vector? When would you use
Vector?
141.​ How does CopyOnWriteArrayList work, and in what scenarios is it useful?
142.​ Explain how the Deque interface works. What are its common implementations?
143.​ What is the use of the EnumSet class, and when should you use it?
144.​ How does WeakHashMap work? What are its typical use cases?
145.​ What is the NavigableMap interface, and how does it extend SortedMap?
146.​ Describe the purpose and use cases of IdentityHashMap.
147.​ How does TreeSet implement its ordering, and what are its characteristics?
148.​ Explain how ConcurrentSkipListMap works and its advantages over
ConcurrentHashMap.
149.​ What is the significance of the Collections utility class, and what methods does it
provide for working with collections?
150.​ How does the ArrayList handle resizing internally? What are the implications of
resizing on performance?
151.​ What are sequential collections in Java, and which interfaces are included in this
category?
152.​ Explain the difference between ArrayList and LinkedList in terms of
performance and use cases.
153.​ How does PriorityQueue differ from other Queue implementations like
LinkedList or ArrayDeque?
154.​ What are the advantages and disadvantages of using ArrayDeque compared to
LinkedList as a Deque implementation?
155.​ How does the ListIterator interface differ from the regular Iterator interface,
and what additional methods does it provide?
156.​ What is the internal DS used in the Executor service ?
157.​ What is the difference between Comparable and Comparator ? Why do we use
Comparator ? Tell me specific use cases ?
158.​ Sort List<CustomClass> without using Streams
159.​ What are the possible ways to sort custom collection objects ?
160.​ What is fail-fast and fail-safe ?
161.​ How do you handle concurrency for collections objects? Why do we go for it? List
some concurrent implementation of it ?
Concurrency
162.​ Why CompletableFuture over Future ?
163.​ What is the difference between concurrency and Parallelism ?
164.​ What are possible ways in java to make your API call Async ?
165.​ What is the difference between synchronized and volatile in Java?
166.​ What are the differences between synchronized and Lock in Java?
167.​ ExecutorService runs tasks in Async or in Parallel ?
168.​ How does the Future interface work, and what methods does it provide?
169.​ What is the difference between Runnable and Callable?
170.​ How do you prevent deadlocks in Java?
171.​ Describe the role of CountDownLatch in synchronization.
172.​ What is the purpose of CyclicBarrier, and how is it used?
173.​ Explain the ReentrantLock class and its features compared to using
synchronized blocks.
174.​ What is the ForkJoinPool, and how does it differ from ThreadPoolExecutor?
175.​ How does the ForkJoinPool work, and what types of tasks is it designed for?
176.​ What is the ThreadLocal class, and how does it work?
177.​ Explain how you can use CompletableFuture to handle exceptions.
178.​ What is Virtual Threads in Java and how does it differ from Normal Threads?
179.​ What is structured concurrency ? How does it work ? tell me some use-case where
you can use it.
180.​ How can you enable Parallelism in Java ?
Stream API
181.​ Why should I use Streams ?
182.​ How to handle exceptions in Streams ?
183.​ How does parallel Streams work if your system has just 1 CPU and 4 CPU ? how will
the behavior be ?
184.​ What is Functional Interface ? Can I keep the default method in it ?
185.​ List some most commonly used functional interfaces you have used.
186.​ What is terminal and intermediate operation in Stream API ?
187.​ What is Flatmap ?
188.​ How flatmap differ from map ?
189.​ Flatten list of list and List or arrays using stream api.
190.​ What is method reference and how can you use it for your methods ?
191.​ You have List<Employee> ,filter Employee if name starts from “A” from given city and
sorted in desc order by city.
192.​ Find the topper from each city
193.​ Can we use Stream twice ? how to print some msg during Stream processing.
194.​ I have a class Employee and Address is embedded inside , group Employee data by
city
195.​ I have an Employee object, group employees by city ,keep in sorted order by city and
I want to see one name and city field as a result.


Scenario based questions
196.​ I have a list of 10K employee data. I want to perform some data transformation and
filtration ,duplicate and want data in sorted order , how do you handle it ?
197.​ I have a list of Employees. How to avoid duplicates?
198.​ Assume you are making a REST Api call from one service to another service. How
will you manage data security and what are possible ways to make remote calls?
199.​ You are calling one service from another , what if the remote service went down OR
not responding?
200.​ I am getting millions of requests in a second through the REST APi, how to handle it
safely to avoid any data loss.
201.​ How you can enable distributed tracing in your microservice architecture.
202.​ Suppose you are going to design your microservice architecture, what are the
common cross cutting concerns you will implement and how. What tools you will use for
the same.
203.​ Suppose you have 20+ microservices, how do you maintain the runtime parameters
like DB details and some other global configurations? What is the best way to handle
such use-cases?
204.​ What is config server and config map and why do we use them in microservices?
KAFKA:
205.​ What is Apache Kafka, and what are its core components?
206.​ What is Kafka Connect, and how is it used for integrating with external systems?
207.​ What is log compaction in Kafka, and when would you use it?
208.​ Explain the difference between a topic, partition, and segment.
209.​ What are Kafka consumer groups, and how do they affect message consumption?
210.​ How does Kafka ensure message ordering?
211.​ How does Kafka ensure high throughput and scalability?
212.​ What is a consumer group in Kafka?
213.​ How do you achieve exactly-once semantics (EOS) in Kafka?
214.​ What is Kafka's replication factor, and why is it important?
215.​ How does Kafka achieve fault tolerance?
216.​ How do Kafka producers handle retries and failures?
217.​ Explain Kafka's partitioning strategy and how it impacts performance.
218.​ What is Kafka retention policy, and how does it work?
219.​ Describe Kafka's consumer offset management.
220.​ How can Kafka handle back-pressure in real-time data processing?
221.​ Explain the concept of exactly-once semantics (EOS) in Kafka.
222.​ How would you monitor and optimize Kafka performance in a production environment?
223.​ Describe how Kafka handles leader election for partitions.
224.​ What are the challenges of using Kafka in a multi-datacenter setup?
225.​ How does Kafka handle fault tolerance at the broker level?
226.​ How would you design a Kafka-based system to guarantee data consistency in the event
of node failures?
227.​ What are the possible ways to tune kafka ?
228.​ How to ensure that KAFKA consumers will not consume duplicate data ?
229.​ What are the kafka publishing strategies ?
230.​ What are the strategies for partitioning ?
231.​ Implement your own Kafka using multi-threading.
232.​ What serializers are required ? How can you customize the behavior ?
233.​ What are Kafka quotas, and how can they be used to prevent resource contention?
234.​ How can you track data loss in kafka ? any tool you have used for it ?
235.​ Why do you need Kafka? How can you design your kafka ? tell me the best practices
236.​ What if your zookeeper went down? Can you avoid zookeeper in kafka configuration ? Do
you see any difference between zookeeper and Kraft ?
237.​ How to make your kafka concurrent ?
238.​ What is kafka offset reset and how can you customize its behavior ?
239.​ Can multiple kafka consumers poll data from the same topic partition ? How does kafka
ensure ordering of msgs in partitions ?
240.​ How does Kafka handle message durability?
241.​ What is Kafka's ISR (In-Sync Replicas), and how does it work?
242.​ What are common challenges in scaling a Kafka cluster, and how do you handle them?
System Design:
243.​ I want to design an Amazon-like service where you can place your order as a customer and I
can check the inventory in the support system.how will you design the system ? can you generate
pattern specific random id for order id where order id should be justifying the order location,zone
and user type.
244.​ Design Phone system where you have to do transactions to the user,partner and RBI. User
transaction should be done on fly ,third party partner transaction should be done 15 days and RBI
transaction should be done on scheduled configuration time. Design the e2e system and draw
architecture diagrams.
245.​ Design a system to take care of money transfer from one account to thousands of accounts at
the same time , how will you handle failure ?
246.​ You have 50+ microservices in env ,how can you design a fault tolerant system with
negligible failure ? How will you establish communication with internal and external systems ?
How can you design an efficient data access layer ? How will you define security and logging ?
NOTE: he wants you to design a system like real time.
247.​ How do you manage data consistency in a distributed microservices architecture? Design the
system flow and architecture with UML diagrams.
248.​ How do you design a scalable and fault tolerance system using microservices ?
249.​ How would you handle API versioning and backward compatibility in microservices ?
250.​ How do you design cross-cutting concerns in microservice architecture ? list them and
explain them on a high level. Design a stable ecommerce system considering the industry best
practices.
251.​ How would you handle database design in a microservices architecture? Suppose you have a
monolithic ecommerce system , how you can convert to microservice based architecture , what
DB you prefer and why ? list the strategies to enable fast access of data from DB. How will you
integrate your new system ? Design the system architecture and data flow.
252.​ What are the spring-cloud components you have used in your current application ? How can
you manage auditing in ms architecture ?
253.​ What are the microservice design patterns you have used so far ? explain it on a high level
with use-case as per your current project.
254.​ What is ACID ? explain in detail with a use case if you have used it in your application.
255.​ What are SOLID principles ? Why do we need it ? explain in detail with realtime examples.
256.​ What are the design patterns you have used so far in your application? Tell me the use-case
where you have used it.
257.​ List some of the design patterns you have used in your microservice based architecture.
258.​ What is SAGA ? When will you go for it? And when to go for a 2 phase commit?
259.​ Can a real time event processing system and draw the architecture.
260.​ Design a simple chat application.
261.​ What are some key points you think while designing the services with multiple components?
262.​ What are cross cutting concerns ? list some of them and how you implement them.
263.​ What is separation of concerns ? What are the benefits of it and how do you do it ?
264.​ You have got a new project to implement , how do you start it, what is the best way to
proceed?
265.​ What is code smells and what are some best practices you follow while coding.
266.​ You have got a new project where you have to start it from scratch , as a Lead/Architect how
will you proceed ? What are the steps and processes you will follow?
267.​ What is system design and what are some best practices while doing system design?
268.​ What is the CAP theorem?

You might also like