This video presents a comprehensive Java Spring Boot interview experience covering essential concepts including circular dependency issues and their solutions using @Lazy annotation, JPA lazy initialization exceptions, bean scopes (singleton, prototype, request, session), global exception handling with @ControllerAdvice, N+1 query problem solutions using DTO projections and entity graphs, secure password storage with encryption, transactional annotation implementation using proxy-based approach, efficient bulk updates with Hibernate batching, API versioning strategies for backward compatibility, Saga pattern for distributed transactions, microservice performance profiling, token expiration handling, rate limiting mechanisms, thread-safe LRU cache implementation, immutable class design with mutable objects, thread synchronization methods (wait, sleep, join), equals/hashCode contract, non-final fields as HashMap keys, JUnit testing of private methods, Maven build commands, CI/CD pipeline stages, and database incident response procedures.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Java Spring Boot 4 Yrs Interview ExperienceAdded:
He is having total four years of experience in Java, Spring Boot and microservices. And guys those who want to give same free mock interview, please fill out the form below in the description. So now let's get started.
Hey hello Vor, how are you?
>> Hello sir, how are you? I'm good.
>> Yes, I'm also good. Shall we start?
>> Sure sir, I'm ready.
>> Okay. So can you please introduce yourself and your recent project in brief?
>> So myself I completed my graduation in 2022. Since then I'm working with metad software services.
>> Recently I worked with a project called DNS that's a >> uh I have a device management SAS application which is actually a m Java based microservices application. I work on microservices like device and user controlling there. It's uh completely the stack depends on Java, Spring, Boot, ReactJS and all our deployments are on AWS and mostly work on the back part using Java and Spring.
>> Okay. Okay. Cool. Um so since you are working mostly from Spring Boot side, I have a question for you. Let's say your spring boot application fails to start with a pin currently in creation exception. What might be the cause or what might be the issue?
>> I haven't seen such kind of exception but as per my understanding I suggest that it might be due to the lazy initialization of the game.
>> Okay. Uh okay. So you have you are telling the solution.
We can fix this issue by using lazy annotation. That's a solution that you are telling. Okay.
>> Uh yep. Yep. So just tell me the I just want to know the cause of this issue.
>> Okay. So let me tell you you must have heard about circular dependencies, right?
>> Yes.
>> So when there is dependency spring >> Yep. Yep. When there is issues in circular dependencies, we usually see this being currently in creation exception and as you already told us, uh we can fix this by lazy annotation as well as constructor injection, right?
>> Yeah. Okay. Okay. And uh what is lazy initialization exception error?
>> Uh lazy initialization exception error generally occurs when uh sorry.
>> Okay. Okay. Uh so it means a lazy loaded JP entities was access outside an open transaction.
>> Okay. So in order to fix this we could use a transaction annotation, right? We could use >> the session is closed. So we cannot access the child intervals after the session is closed.
>> Correct. Correct. Okay. Tell me what happens when you declare two beans of the same type without any qualifier.
>> So declaration will give uh we can have beans of same type without but we'll have to give at the primary. So >> we are not giving at the rate primary and also we are not giving at the rate qualifier notation. Then what would happen?
>> It will give exception so that the spring cannot have the bean of same type like multiple beans of the same type.
>> Yep. Yep. Yep. That's correct. Uh spring throws no unique bean definition exception in such cases unless marked with primary annotation or injected using qualifier annotation.
>> Yes. Yes. So can you tell me what type of beans we have scope beans?
>> We have multiple scopes like uh singleton prototype application >> session.
>> Okay.
>> And request >> and what's the default one that spring boot uses?
>> Default is singleton which make sure that only one instance is there for the whole application website.
>> Okay. Tell me the case where you want to use prototype scope bin but not singleton bin.
>> For such cases when we want the object creation on conditionally like on particular requests.
>> Mhm.
>> So we don't want the object data to be shared across the whole application context.
>> Okay.
>> So in such cases most people lose.
>> Correct. Correct. Um okay. Moving ahead.
Let's say you have created a rest controller advice annotation. Right but your global exception is not getting caught. I'm interested to know the reasons what might be the issues.
>> So mostly control we use to handle the global exceptions of the spring conditions >> and if it's not catching our exceptions.
>> So this might be due to in exception handler we missed those exception to handle.
>> Mhm. So in exception handler we can handle different type of exceptions and when such exceptions occur in our application then those exception handlers are triggered and they are responsible to send the response back to the client.
>> Yep. Okay that's correct. Um hey guys uh before moving to the next question I want to share something important with you. Actually we prepared from our interview preparation kit and cracked multiple interviews. We have also referred him to the multiple companies.
So guys, let me tell you this interview preparation kit has four main parts.
First is complete interview preparation material. It is a step-by-step material made by me expert and MNC's interviews.
99% of the questions asked in interviews are covered in it. Second is to real enterprise client projects. Code and video recorded sessions are there and you can add this in your resume. Okay.
Third is lifetime chat support. Here you can ask your doubts anytime. Fourth is referral support. Here we help you to get referred to the top MNC's. So basically the material is organized as per your experience level and covers Java, Spring Boot, Spring Security, Spring Tra, JPM, microservices, Kafka, Van, Git coding questions, TB coding questions and many more. Okay, you can buy just the complete interview preparation material or the full kit with project supports and referrals. I have added the links in the description below. So now moving to our interview and guys before moving to interview since we have vibbor so we can ask for a feedback. So vibbor can you please uh share some feedback?
>> Yeah. So I have been preparing my interview from those notes only. It's helping me a lot clearing my core concepts and helping me reading interviews and give me confidence to answer in the interview.
>> Okay.
>> Cool. Thank you. I'm moving ahead. Um okay. So let's say you have added a custom configuration class.
Okay. Yeah.
>> But it's not being picked up by Spring Boot.
I just want to know the issues behind this.
>> So if you put a uh custom configuration class which is all which is basically uh meant to provide the custom beans or bin definitions. So main reason can be within the class we don't have a method at at the annotations and they're not actually passing an object or returning an object of type object that should be pro processed as a do >> second issue I can think of is the class itself is not annotated with add configuration annotation >> correct >> yeah these two I think >> and maybe class is outside the main spring boot applications scan base package.
>> Yeah, that can also >> it's also the package.
>> Okay. So, I'm I just want to know did you face N plus1 query problem in your career and if yes then how did you tackle that?
>> Yeah, it happened with us. So mostly when it happens you know we have a parent entity and it has a class child in the district. So if we have a parent entity let's say a user and it has its orders as a child entity. So when we query a parent the child along with it is also query. For example, if at the parent has n number of orders. So it will be n the number of orders plus one the parents itself. That's called the n +1 problem. We have faced that it causes a lot of uh work on the database. It makes the application slow. To fix this what we used uh we can use uh DTO projections first of all apart from that we can use entity graph and also we can use join page also with the entity.
>> Yep that is 100% correct. Um what's the difference between entity graph and join fetch?
>> Uh joint fetch is basically applied directly to the entity. I'm I'm quite confused here. Entity graph is written over the query the JP query.
>> Okay, cool.
>> Um, tell me how would you ensure sensitive data like passwords is not persisted accidentally with JPA?
>> So sorry I didn't get that question.
Persisted.
>> Let's say you are working. Persisted means saving into the database sensitive data.
>> Okay. Okay. Okay. Got it.
>> So what we can do? So mostly we direct we don't directly store sensitive data in your database. We uh usually use encoders.
>> Mhm.
>> So for example in uh spring boot we have in password encoder class. So it is used by authentication manager etc. to >> decrypt or decrypt passwords and all. So we usually store the password as a in encrypted form which is just one way encryption. We cannot uh get the password back from the encryption. So that way we can secure the data.
>> Yep. Yep. And also we could exclude listeners using transient fields marks field like transient annotation. Right.
>> Yeah. That was not serializable.
>> Mhm. Correct.
>> Okay. So did you get a chance to use transactional annotation?
>> Yeah I have worked with that.
uh tell me how it works behind the scenes.
>> So transaction annotation uh basically uses proxy based approach.
So I mean uh the beans we use in our application are basically covered or we can say wrapped around the proxies. So when we call the actual method there is proxy proxy working behind that.
So the proxy take care of the transaction creation of the transaction doing the rollouts and committing the data or making the rollouts achieve.
>> Mhm.
>> Okay, that is correct. Um have you used flush method inside a transaction?
>> Uh yes I think flush is basically used to move the data in persistent context to the actual database. So after flush it does the actual SQL query to store the data >> into the database. So it moves data from persistent context to the actual database.
>> Okay.
So let's say uh you are asked to do bulk update of 10,000 records efficiently by using spring data JP without loading them into the memory.
How would you do that?
>> First of all we should enable the hibernate. We have in hibernate that is called batch. uh >> batching in hibernate there is one uh sorry in properties.xml XML we can put hab dot batch size so it will make sure that the uh the insertion happens in batch instead of doing multiple round trips to the database. Secondly even if we do the batch there but still if you load the whole like for consider itself 10,000 one lakh entries into the persistent context even persistent context is also a type of memory. So we cannot load all the data into that memory. So instead of that what we can do we can traverse over the data and do the flush and clear.
So first we persist the data then do we flush then do we clear. So in that way also we don't overwhelm the persistent context. So our application don't get slow due to or it won't give the memory exceptions to us also.
>> Okay. Got it. That's correct.
Um, how would you ensure backward compatibility of the APIs when multiple clients are involved?
>> Okay. So, this comes to us when we do the versioning also.
>> So, when we so we basically use the uh so a URL based versioning. So, we have V1 and then we have V2 also. So to ensure backward compatibility what we did was so for an instance of time we put both of them alive and working on the server and then gradually we requested in our headers of the old APIs for the clients to shift to the new APIs like newer version of the application.
>> Mhm. And we try so to make sure the application is backward compatible on the application level. We supports both kind of data for the from the old APIs also and the new APIs also. Even the databases were built to support both kind of data without giving an exception and once all the clients or all the traffic is diverted to the new APIs. So we gradually remove the dependency of the old API structure.
>> Okay. Cool. Can you explain the saga pattern and also tell me when you would prefer it over two PC and microservices?
>> Saga pattern is basically used when we have transaction distributed across microservices.
>> Mhm.
>> So we see sorry I'm not much.
>> Okay.
>> Yeah. Yeah. It's fine. So saga pattern as you already told it's a series of local transactions plus compensating action right we should prefer over two PC uh due to loose coupling as support and better fault tolerance in saga pattern right okay let's say you have a three microservices in a chain and one is slow >> how do you isolate which one and fix it like how would you identify which one is slower and fix it >> okay so we have three microservices in chain.
>> Mhm.
>> Uh let's say A calls B and B calls C and the response is written in in the same chain once. So to identify uh let's say to identify which microservices is working slow.
>> Yep. Yep. Uh let me tell you an example.
Let's say uh we are just calling one API and that's hitting our microservices A and microservices A is calling B and micros service B is calling C and then microservices fetching some data and returning in a chain format but we have observed like in our API uh top in the top level in our API we are seeing some slowness in the API there are some latencies but we don't know due to which microservices the response is getting slower So uh if someone askked you to give uh I I mean to find the root cause and also how would you do that?
>> Uh first of all uh we can use uh on application level basically >> what we can use is we can use uh AOPS like uh there is we have around AOP >> which starts or which actually helps to calculate the time a function takes to you know actually execute and get the result back. So this way we will get to know which function basically is causing the delay to apart from them the delay can also be coming from the database queries also.
>> Mhm.
>> So what we can do we can put a profiling across the services. We can put profiling with to service B and to service C also. we can calculate the time and we can easily I mean get how much time each of the services is taking to actually process the response and sends us back to the colleague service.
>> Mhm. Okay. Um and also we could use distributed tracing right fix index optimization.
>> Okay.
Mo moving ahead in a O2 secured micros service the token expired during a long async process. So how would you handle it?
>> Token expires within the song. So the request has come to us. We are processing it and the process is going asynchronously.
>> Mhm.
>> And the token expires in between of that asynchronous processing.
>> Correct. Correct.
So uh since the request has reached to a server and we started processing of the request so we should not give an you know unauthorized access to the user it will be you know it will be a bad user experience to the end user. So what we can do we can let the current request process we can send the response back to the end user >> and whenever there is a next call made to us since the uh the token is already expired so he will get another access and he will need to login again something like that.
So we can handle it in such way as per my understanding.
Okay. And we could also use refresh tokens reauthentication system. We can check the token validity before action like we'll be able to cover all our operations like uh just before action.
>> Okay.
>> Okay.
>> Okay. Um do you know the concept of rate limiting mechanism?
>> Yeah.
>> Why do we use rate limiting?
Uh so mostly rate limiting is done just to secure our back end application our infrastructure from getting spam calls.
Let's say if someone uh just do a bot calls on our application >> and that bot calls can raise the usage of our application and the genuine users which want to use our application may face low latency etc etc. to save our application from that we do.
>> Okay. Someone asked you to implement a thread save LR cach right. So how would you do that?
>> Let's say caching.
>> So to make it thread safe we can use the collections which are actually thread safe in multi environments.
For example, mostly the caches are used or we store these in hashmaps basically.
So we can use concurrent hashmap which is actually a very good uh thread safe data structure.
So yeah we can implement using that.
>> Yep that is partially correct. Our first thing is base thing is linked hashmap.
We have to use linked hashmap with access order and override remove lash entry method and wrap it in concurrent hashmap with custom logic.
>> Okay.
>> Okay.
>> Um why linkage hashmap is used in LRU because it maintains insertion or access order. It enable easy removal of the least recently used item.
>> Okay. Um can you tell me what issues can arise if a class is immutable but contains a mutable object?
>> Yeah. So for example if class is mutable uh immutable and contains a mutable object let's say of date time object or something.
So when we get the uh we have a object of the class and that uh within the class we can get the object of that mutable mutable class also. So once we get the object that object is actually reference to the object it's not actually the it's not the value of the object it's the reference of the object.
So if we make any changes to the reference object so it will actually reflect in the imitable class object.
So which will break the law of immutability.
>> Correct. And what's the solution?
>> To save to save this what we can do when we store the object into uh to the when we set the object to the imitable class what we can do instead of saving the actual object we can clone the object and save it.
And while retriving also when we retrive the object instead of giving the real object back to the calling method or operation. So we can give a clone of that object.
>> M >> so cloning helps here so that the changes are done on the clone object not on the actual object inside the class.
>> Okay. Okay. So can you can you tell me the difference between weight, sleep and join method in a multi-threading uh environment.
So wait what wait does is for example the current thread calls wait >> that thread goes in a waiting state >> okay >> on that object and waits until another thread calls notify notify all so that it gets in continuation state >> uh second what was the second >> um wait and uh one second wait and sleep and join >> sleep is basically uh sleep makes the trade in waiting state indefinitely. For example, we can put sleep and put a timer inside the put time inside it. We we want to make the thread sleep for this time period. After the time period executes, it regains the runnable state >> itself. So we don't have to manually do anything. And third was join method.
What join method does is if we start up with we start a thread like t1 start and we want that the thread executes >> only I mean the thread execution first happens and then only we should do something after thread execution. So what we can do we can use t1.jin t1.jin make sure that the thread first executes then only the program will go on.
>> Correct? Okay. So tell me you override equals method but forget hash code method. what kind of production bug can arise?
>> Uh so basically we override the equals method but don't so there is a contract between equals and hash code when we use it in a hash map basically. So if two equal methods giving if if if two objects having uh equality when we compare it with equal methods >> Mhm.
>> Okay. But they are not having the same hash the hash code output then it will give a bug in our application.
>> Mhm.
>> For example, we have an object of user.
User name is uh let's say before and it it has an ID of one. So we create two objects with the same name and same ID.
So we do equals on ID and the name but we do hash on something else.
>> Mhm.
So technically these are the same objects but when you put into hashmap since the hash code is different for both of them they will go to two separate buckets >> and even when we do uh we want to get so uh every time we do a push and get it will be like it will be uh what we can say I'm not getting a proper word for it but for but the the way I said that you know uh So basically the same object it will go to two different buckets instead of going to the same bucket.
>> Mhm. Let's take an example of set. So set.contains may fail unexpectedly leading to duplicates or incorrect uh values due to inconsistency between equals and hash code. Right? Okay. So let can you please tell me what are the consequences of using non-final fields in a class used as a key in a hashmap?
>> Nonsequences.
Okay. So for example we have the example I just gave right now. Uh let's say we have the key on the basis of name and ID field. So if we use a non-final field for that and we store that object for now it's view and ID is one. We store that in the hashmap and since it's a non-final it may get changed later on like anyone can come and change the value >> later on when we try to get the object from the hashmap. Since the key has changed, we won't be able to fetch the object.
>> M.
>> So this will give a potential bug in our application.
>> Correct. Okay. So how would you write a JUnit test case when method is private and there is no setter in public constructor.
>> Sorry.
>> Okay. Mhm.
>> Uh we can use reflections to instantiate and access private fields and methods.
This is the first thing.
>> Yeah.
>> Okay. And we can also refactor to use package private constructor or inject via factory method.
That's the second thing.
>> Okay.
>> And we can also use tools like power mob if absolutely needed.
>> Got it.
>> All right. Okay. Um have you used have you worked with Docker and Kubernetes?
Do you have experience?
>> Uh not actually. Basically our uh our complete infrastructure was AW based. So we used uh elastic container services and all which manages this all.
>> Okay.
>> So get changed.
>> Yep. Okay. So tell me um what's the difference between provided and compile scope in Maven provide?
>> Yeah. So do you are you working with Maven or Gradle?
>> It's a Maven.
>> Maven. What's the difference between Maven clean and Maven install?
>> Maven clean is uh basically cleans the previously built projects.
>> Mhm. So it just cleans those files and artifacts whatever was created over here.
>> What install does is install packages them all together like making a new build >> but along with installation it runs the test cases also and we usually do Maven play and install together so that we just clean the old work and create the new build.
>> Mhm.
>> New window jar kind.
>> Okay. Um let's say uh your pipeline. So have you worked with pipeline CI/CD pipeline?
>> Yeah, CICD pipeline. Yeah.
>> Okay. So what are the stages there in your pipeline?
>> So it just build uh test and deploy.
>> Okay. Got it. Um let's say your system went down at 3:00 a.m. due to a DB overload.
So in your team, what's the plan to recover or to work on these type of issues?
>> So the system goes down due to DB overload at 3:00 a.m. and midnight. So first thing will be uh so we have alarms cloud alarm set for that.
>> Mhm.
>> Everyone we will get the emails for the DB overload when the system is down etc. So after that we start analyzing like for example the DB was load for service A. So we analyzing it DB logs like why it is going like if like why it is happening there are more request than >> if the DB connection pool has exceeded.
>> Mhm.
>> Like what was the root cause we do root cause analysis properly first of all like what was the use case?
>> Okay.
>> We yeah >> okay. Um now vibbor uh I'm just going to ask a few coding questions. Uh can you please share your screen and open any editor whether it's a local or online?
>> Yep.
>> Okay. So the question is you are given a number n okay and n minus one elements.
Okay. And let's take an example of n is equal to 6.
>> Okay.
>> Okay. And there will be there would be five elements then. Right. And elements should be must be unique. Okay.
That's the first thing. And elements should be there from 1 to n minus one.
Sorry 1 to n.
For example, if n is equal to six, then element can be 1 2 3 4 5 6.
>> Okay. Uh now there is one number missing in that n minus one array >> element. So you have to find that missing number.
>> Okay.
So it will have it may have 1 2 3 4 5 6.
>> Let's say uh 1 2 3 4 five. Yes. Yes.
>> So we have to find the missing >> correct in the best way.
Okay. So what you are trying to do?
>> Uh so basically I created a default array of fil with minus one of size six.
So it will have -1 -1 or six.
>> So that will be the default value of >> okay >> I'm traversing over the second array.
And you are putting zero except >> uh the six right >> that is missing. Yeah.
>> Okay.
>> Just then checking if any of the uh >> Mhm.
>> array uh any of the element with the defaults is having the default value means that is not occurred into the array.
>> Okay.
>> So that's our answer.
>> Yeah. Yeah. Please do it and uh this is also one of the way but this is not the best way to do this. Um yeah yeah please do it uh first then we'll discuss other approach.
system I think spelling mistake of system okay so let me tell you uh another approach or let's okay let's hold on let's not do this I just got your point uh you are just putting everything minus one and then uh in the next iteration you are just putting zero except the missing number and then you are putting if the if if the element is minus 1 it mean that number is missing okay there is another way to do that by summing up uh let's say one sum of the array 1 + 2 + 3 + 4 + 5 right and uh uh you have to find and uh we can also uh find the sum of natural number for example if n is equal to 6. We can count the uh 1 + 2 + 3 + 4 + 5 + 6. Then subtract the sum of natural number minus this sum of array.
Then we will find the uh missing >> missing number from them.
>> Yep. Yep.
>> Okay. So yeah.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
🚀 BCS613C Compiler Design | Module 1 to 5 Schema Evaluation 🔥 | VTU 6th Sem 💯 #VTU #bcs613c #exam
Pranavaa-y4y
104 views•2026-06-02











