Java Spring Boot 5 Yrs Interview Experience [He Answered all] — Transcript
Full transcript
- 0:00Hey guys, today we have Mehboob and he
- 0:02is having total 5 years of experience in
- 0:04Java Spring Boot and Microservices. And
- 0:06guys, those who want to give same
- 0:08framework interview, please fill out the
- 0:10form below in the description. So, now
- 0:11let's get started. Hey, hello Mehboob.
- 0:14How are you? Yeah, I'm doing fine. How
- 0:16are you? Yes, I'm also good. Shall we
- 0:18start? Yeah, sure. Okay. So, Mehboob,
- 0:21can you please introduce yourself and
- 0:22your recent project in brief? Yeah, so
- 0:25my name is Mehboob Jilani. I'm a Java
- 0:27back-end developer.
- 0:28I'm having a total of 5 years of
- 0:30experience in back-end development. And
- 0:33my coming to my recent project, it is
- 0:35called Rogers Communication. Mhm. Uh
- 0:38where we provide internet-based products
- 0:40to users like uh
- 0:43Wi-Fi, streaming, home security. And
- 0:45currently, I am working in home security
- 0:47team where we provide, you know,
- 0:50security cameras, alert monitoring
- 0:53monitoring system to users. Got it. Got
- 0:55it.
- 0:55>> Yeah, that's it briefly about me. Okay,
- 0:58thank you. So, it is based on a Spring
- 0:59Boot? Yeah, yes. The back-end systems
- 1:02are implemented in Java Spring Boot.
- 1:04Java Spring Boot. Okay. So, uh Mehboob,
- 1:07let's say your current project is taking
- 1:10too long to start because of heavy bean
- 1:12initialization, right? So, my question
- 1:15is how could you optimize startup time?
- 1:18Okay, so if it is taking longer time
- 1:22due to bean installation, then
- 1:24in Spring Boot, we are having an option
- 1:26called at the rate lazy initialization.
- 1:28So, when we implement lazy
- 1:30initialization,
- 1:31um when the Spring Boot boot when the
- 1:34Spring Boot application is starting, it
- 1:35will inject
- 1:36create and inject only those bean which
- 1:38are required to start the server. And
- 1:40the remaining beans will get created
- 1:41injected based on the requirement. So,
- 1:43in that way, we can optimize the startup
- 1:46time.
- 1:47Yep, yep, yep. That's correct. We could
- 1:49use lazy initialization, right? Okay,
- 1:52moving to the next question. A REST
- 1:53endpoint is returning outdated cached
- 1:56data instead of fresh data.
- 1:58Right? So, my question is how a REST
- 2:02endpoint you have created a REST
- 2:04endpoint, right? Now, it is returning
- 2:06outdated cached data instead of a fresh
- 2:09data.
- 2:10Okay? So, how would you debug and fix
- 2:13this? Okay, so
- 2:15if it is a, you know,
- 2:17which type of endpoint you is it a get
- 2:19or, you know, or is it a post? Uh let's
- 2:22assume a get endpoint. Okay, if
- 2:25uh it is returning the if get mapping is
- 2:27returning, you know, outdated data
- 2:30I will try to check whether they have
- 2:32implemented with ID with key or not
- 2:35because we can implement the caching
- 2:37with just using at the rate cacheable.
- 2:40But, if you don't implement based on key
- 2:42then it won't uh update the data. So, I
- 2:45will check whether it is updated with uh
- 2:47key or not. If it is updated with key,
- 2:50then we will I will check whether
- 2:52whenever we are, you know, doing post or
- 2:54put operation, whether we are updated
- 2:56with a
- 2:57uh cache put or not.
- 2:59So, that whenever if you use with cache
- 3:01put, whenever if there is any kind of
- 3:02updation happen, the cache manager will
- 3:05automatically update the cache.
- 3:07So, in that way we can fix that issue.
- 3:10Okay.
- 3:11Okay, so and also uh we should look a
- 3:16TTL time to live settings, right?
- 3:19And as you already told me, cache key.
- 3:22That's also correct. And also uh we
- 3:25should test these things with cache
- 3:27evicted or cache manager, right? Okay.
- 3:30Okay, cool. Uh moving ahead, you have
- 3:32two Spring Boot microservices. Okay?
- 3:35They are communicating via REST
- 3:37endpoints.
- 3:39Okay? One is working fine as expected.
- 3:43Okay? One frequently times out under
- 3:46load.
- 3:49Okay. Okay. Okay. So, how would you
- 3:51handle this situation or scenario?
- 3:55So, if you do if it is do going to not
- 3:58due to load, I will check whether our
- 4:00load balancer is working properly or
- 4:02not. If it is, you know, if the entire
- 4:04load is
- 4:05going to only one server, so it will be
- 4:07very difficult for that application to
- 4:10work. So, we'll check whether our load
- 4:12balancer is working or not. And along
- 4:14with that, if our load balancer is
- 4:15working fine, then we can check whatever
- 4:18the code we have written, we can analyze
- 4:20the code. Okay, whether we have
- 4:22implemented, you know,
- 4:24uh for loops with order of n squared.
- 4:26Okay, if we if they are there, then we
- 4:29need to optimize them order of
- 4:31n for loop so that it won't take long
- 4:34longer time.
- 4:35Uh we can implement, you know,
- 4:37resilience4j for this
- 4:39fixing.
- 4:40Yep, yep, yep, that's correct. We could
- 4:42use resilience4j. And we could use uh
- 4:46timeouts like we can tune timeouts,
- 4:48right?
- 4:49And but yes, your answer is correct.
- 4:51Okay. Uh moving ahead,
- 4:53um let's say you have an API
- 4:57that should be publicly accessible.
- 5:00Okay? You have an API that should be
- 5:03publicly accessible, but
- 5:06another endpoint should require
- 5:08authentication. Okay. So, how do you
- 5:10configure this in a Spring Security with
- 5:13a Spring Boot?
- 5:15Yeah. Yes, so in Spring Security when we
- 5:17are implementing or overriding a
- 5:19security filter chain, we can implement
- 5:21them. So,
- 5:23during this there is a option called
- 5:25permit all and authenticated. So,
- 5:27whichever the public endpoints are
- 5:28there, so by using the request matcher,
- 5:31we can
- 5:32give that endpoint and then we can
- 5:35do like permit all so that it won't need
- 5:37authentication. And for the remaining
- 5:39all the other endpoints, it should need
- 5:41authentication because we will use
- 5:43permit all and then we can use
- 5:45authenticated so that all the public
- 5:48endpoints don't need authentication.
- 5:50Yep, yep, yep. That's correct.
- 5:53Okay.
- 5:54Hey guys, I want to share something
- 5:55important with you. Actually, Mehboob
- 5:58prepared from our interview preparation
- 5:59kit and cracked multiple interviews. We
- 6:02have also referred him to the multiple
- 6:04companies. So guys, let me tell you this
- 6:06interview preparation kit has four main
- 6:08parts. First is complete interview
- 6:09preparation material. It is a
- 6:11step-by-step material made by me, expert
- 6:13in MNCs interviews. 99% of questions
- 6:16asked in interviews are covered in it,
- 6:18okay? Second is two real enterprise
- 6:20client projects. Code and video recorded
- 6:22sessions are there and you can add this
- 6:24in your resume. Third is lifetime chat
- 6:27support. Here you can ask your doubts
- 6:29anytime. Fourth is reference support.
- 6:31Here we help you to get referred to the
- 6:33top MNCs, okay? So basically, the
- 6:35material is organized as per your
- 6:37experience level and covers Java, Spring
- 6:39Boot, Spring Security, Spring Data JPA,
- 6:41Microservices, Kafka, Maven, Git, coding
- 6:44questions, stream web API coding
- 6:45questions, and many more. You can buy
- 6:47just a complete interview preparation
- 6:49material or the full interview
- 6:51preparation kit with project supports
- 6:52and references. I have added the links
- 6:54in the description below. So now, moving
- 6:56to our interview. And guys, before
- 6:58moving to our interview, since Mehboob
- 7:00is here, so we can ask for a feedback.
- 7:02So Mehboob, can you please go ahead?
- 7:03Yeah, so I have prepared by using your
- 7:06interview preparation kit and it helped
- 7:08me a lot. Okay. Actually, I'm able to
- 7:11crack my interview, so yeah. Thanks for
- 7:13that. Okay, okay. Thank you.
- 7:15Moving ahead, guys.
- 7:17So Mehboob,
- 7:20let's say your application works locally
- 7:24but fails to connect to the database in
- 7:26production.
- 7:28Okay?
- 7:29What steps would you take to analyze the
- 7:32issue and fix it?
- 7:34Okay,
- 7:35let me think about it one second.
- 7:40Yeah.
- 7:41Okay, so when we are working in our
- 7:43local right? So, whatever
- 7:47the in application of properties,
- 7:48whatever the data source credentials we
- 7:52have given, we know that it will be
- 7:54fine. But when we are going into prod,
- 7:57okay? So, most of them we don't get
- 7:59hardcoded values. Mostly we will fetch
- 8:01it from, you know, from either config
- 8:03server or some other profiles. Mhm.
- 8:06>> Okay. So, I will check when we are
- 8:09defining in the config server whether we
- 8:11defined the proper credentials or not.
- 8:14Okay.
- 8:14>> Okay. Then after that if you are If you
- 8:17are fetching If you are using profiles,
- 8:20whether we started with the correct
- 8:21profile or not. Like we we We can have
- 8:23multiple profiles, right? Okay, if it is
- 8:26going for prod, the only prod profile
- 8:27should be activated. So, I will check
- 8:30whether we have activated the prod
- 8:32profile or some other profiles.
- 8:34So, these two things we can do.
- 8:37Uh other things I'm not sure about them.
- 8:39Yep, yep, yep. Uh that's correct. And
- 8:42other than this, uh we could check SSL
- 8:45certificates, connection pool size,
- 8:47right? And
- 8:49logs as you have already told this,
- 8:51okay?
- 8:52>> [clears throat]
- 8:52>> Now, moving ahead,
- 8:54um Mehboob, one of your API takes too
- 8:57long because it loads a large data set.
- 9:01Okay? Mhm. Yeah. So, how would you
- 9:04improve the performance?
- 9:07So, if the API is slow due to the large
- 9:10data, then we can implement pagination.
- 9:12Okay. When we implement [clears throat]
- 9:14pagination, so rather So, instead of
- 9:18sending the entire data, we can send the
- 9:20data in chunks based on the user
- 9:21request. Mhm.
- 9:23>> Okay. In pagination, there is a
- 9:25We will have, you know, what is a page
- 9:27size and what is a page number. Mhm.
- 9:29>> Based on that, we will fetch only that
- 9:31particular data and we will send that
- 9:33one. In that way, we can avoid this
- 9:35issue.
- 9:36Okay, that's correct.
- 9:38Moving ahead,
- 9:39let's say you have sensitive configs.
- 9:42Maybe DB passwords, maybe API keys in
- 9:45application properties or application
- 9:47YAML, right? So, then my question is how
- 9:50would you secure them?
- 9:54Okay, so
- 9:56in this scenario, it is
- 9:59the better way is we won't store actual
- 10:03values in our application or properties.
- 10:05Mhm.
- 10:05>> Okay?
- 10:06So, rather than this we will have our
- 10:09config server separately, okay? In that
- 10:12config server, we will
- 10:14store all these kinds of values. And
- 10:17whenever we are starting our server, our
- 10:19application will fetch those values from
- 10:21that config server.
- 10:22Mhm. And then it will use to start the
- 10:25application.
- 10:26So, this is one way. Another one way is
- 10:29if you are using K8s to deploy your
- 10:32application. Mhm. Inside K8s, we will
- 10:35define those variables and we can paste
- 10:38the placeholders in our
- 10:40application.properties,
- 10:41okay? And when we start when we are
- 10:44going to start our application so, the
- 10:46K8s will map those fields by using
- 10:49config maps and it will
- 10:52inject those values. So, in that way we
- 10:54can
- 10:55uh
- 10:55protect our values. Mhm. Our properties,
- 10:58we can say.
- 11:00Okay, cool.
- 11:02Moving ahead, a scheduled job in your
- 11:05Spring Boot application is running twice
- 11:07in production even though you have
- 11:10deployed only once.
- 11:13What might be happening?
- 11:16Okay, so are you saying about a Spring
- 11:19Batch processing?
- 11:21No, no.
- 11:23Scheduled jobs. Yeps.
- 11:25Okay, scheduled jobs. Okay, so in that
- 11:27case so, I will check in
- 11:30by using which
- 11:32method I have
- 11:34you know, deployed it whether I have
- 11:35used I have used a fixed rate or fixed
- 11:37delay. Mhm. In this [clears throat]
- 11:39scenario, whatever we
- 11:41we defined there is a most probably
- 11:44there should not be a possibility of,
- 11:45you know, executing that job multiple
- 11:47times. But if you deploy by using cron
- 11:50job, we will give the cron command.
- 11:52Okay.
- 11:53If there is anything issue in that cron
- 11:55command, there is a chance of executing
- 11:59that job multiple times. So, I will try
- 12:01to fix that cron job.
- 12:04And it will fix the issue.
- 12:06Yep. Yep. That's correct. And also, one
- 12:08more thing I would like to highlight.
- 12:10Um we can also check whether multiple
- 12:13application instances running.
- 12:16Right?
- 12:17Or Or multiple schedulers enabled.
- 12:20Right?
- 12:22And also, what you have already told us.
- 12:25Okay?
- 12:26Okay.
- 12:27Um so, your REST API allows file
- 12:31uploads, but user complain about large
- 12:35file failing silently.
- 12:38Mhm. Okay. So, how would you fix this
- 12:41issue?
- 12:43So,
- 12:45Sorry. Yep. So, in the Spring Boot
- 12:49application.properties, we can define
- 12:51one
- 12:52key value, spring.max-file-upload. Okay?
- 12:55So, in-built I think the Spring Boot
- 12:58supports 1 MB file. Okay? I guess so.
- 13:01I'm not sure. I guess. But if user is
- 13:04trying to upload, you know, huge uh size
- 13:07file, okay, then we need to
- 13:10uh manually define
- 13:12to Spring Boot that you can allow this
- 13:14much of file size in your
- 13:15application.properties. Okay?
- 13:18And this way we can fix this issue.
- 13:21Yep. Yep. Yep. That's correct. Uh we can
- 13:24define our maximum file size or maximum
- 13:27request size, right?
- 13:28>> Yeah. Uh it could be done like uh
- 13:30spring.servlet.multipart
- 13:33{hyphen} max {hyphen}
- 13:35>> multipart Uh something like that. Okay?
- 13:38Yep. Uh moving ahead. After a Spring
- 13:41Boot version upgradation
- 13:44Okay, after upgrading Spring Boot
- 13:46version, your custom bean stopped
- 13:49working because a default bean started
- 13:52overriding it.
- 13:54So, how would you fix this issue?
- 13:56>> Okay.
- 14:01I don't know.
- 14:03Oh, okay. So, like I'm I haven't tried
- 14:07this one, okay? But what
- 14:09my procedure will be first I will try to
- 14:12go through a little bit of documentation
- 14:13of that new version,
- 14:15and I will try to check whether if any
- 14:17of the like whatever I have used when
- 14:20the whether any of them is got
- 14:21deprecated or not. Okay? If it gets
- 14:24deprecated, then I will try to
- 14:27uh convert I will try to change them by
- 14:29using the whatever the newly updated
- 14:31one.
- 14:33Uh this is one thing we can do.
- 14:35Uh
- 14:37Yeah, actually like I'm not sure about
- 14:39this like how can we fix it? But
- 14:41this is one thing I will do, but Okay.
- 14:44Uh
- 14:44I think you have already know the
- 14:47answers, but let me tell you. Uh we
- 14:49could use primary qualifier or disable
- 14:51auto configuration.
- 14:54Oh, that is for
- 14:56uh uh like to
- 14:59Okay, which which bean we need to use,
- 15:00right? Yeah, yeah. Let's say
- 15:02our custom bean stopped working because
- 15:04a default bean is started overriding it.
- 15:08Right? Uh
- 15:09we can disable the default bean by
- 15:11excluding or we can make our bean
- 15:12primary.
- 15:15Yeah, yeah, yeah. I know this plantation
- 15:16with that work, but yeah, yeah. Yeah, I
- 15:18said it to you already.
- 15:21You knew the answers. Okay, moving
- 15:23ahead.
- 15:24Um your API endpoint returns an empty
- 15:27JSON response even though the data the
- 15:31DB has data.
- 15:33Okay. What would be the possible causes?
- 15:38Well, okay, so what in possible causes
- 15:42so first thing will be um in most of the
- 15:45interface application when we sending
- 15:48data to customer, we won't send the
- 15:49entire data. We will use DTOs and we
- 15:51will send only the required data to
- 15:53user. Okay.
- 15:55>> Mhm. And we will map the we will map
- 15:57them by using the actual data from DB
- 15:58and we will send it to user. I will
- 16:00check whether during the mapping
- 16:02whatever the fields we are sending to
- 16:04user, okay, whether they are getting
- 16:06actual data from DB or they they are
- 16:09getting set with null. That's one thing
- 16:10I can do.
- 16:12And
- 16:13another thing I can check
- 16:15in our DTO files whatever the
- 16:17annotations I have mentioned, there is
- 16:19an annotation called, you know, JSON
- 16:20include nonnull. In sometimes, even the
- 16:23JSON itself it will exclude some fields
- 16:26if it didn't find the value.
- 16:28So I can check whether it is working as
- 16:30expected or not.
- 16:32Okay. Cool.
- 16:34Um so yes, that is correct and we could
- 16:37also check Jackson serialization issues.
- 16:41Missing getters. That's a basic one. I
- 16:43mean
- 16:45Yep, yep. Uh moving ahead.
- 16:47Um in your system, uh you have 10 Spring
- 16:50Boot microservices, right?
- 16:53And managing configurations like um DB
- 16:56URLs, feature flags, etc. separately has
- 17:00become painful.
- 17:02You got it?
- 17:04Yeah.
- 17:04>> So how how would you handle centralized
- 17:06configuration management?
- 17:10Yeah, so
- 17:11sorry.
- 17:12So I will implement one
- 17:14particular service as a config server.
- 17:17okay? That config server will have all
- 17:19the
- 17:20DB configuration, all the required
- 17:22properties
- 17:24as per our requirement, okay? And none
- 17:26of other applications will have those.
- 17:28And I will use that beans. And our
- 17:31application, whenever they need to
- 17:33start, they will fetch those values from
- 17:35the config server only. In that way,
- 17:37whenever we need to update or we need to
- 17:39change any kind of fields, we can
- 17:41able to go and change in only one one
- 17:44application rather than
- 17:45updating in all the 10 servers.
- 17:49Yep. Yep. Yep. That's correct.
- 17:52Okay.
- 17:53So, can you tell me how would you design
- 17:56the checkout process for an e-commerce
- 17:58platform?
- 18:00Right, like cart, payment, order,
- 18:02inventory update by using Spring Boot
- 18:04microservices.
- 18:08Just answer me brief.
- 18:10You don't have to answer it
- 18:12with too much details. Yeah, so yeah, so
- 18:15first of all, user
- 18:17will logs into
- 18:19e-commerce application.
- 18:22Then first of all, he will add the item
- 18:24to cart, okay? Then cart operation will
- 18:26get performed, and he will able to see
- 18:28all his product details in the cart.
- 18:30Then he will go to the
- 18:32payment options, okay?
- 18:35There
- 18:36we will implement our payment service
- 18:39separately, okay? And then wherever
- 18:42whatever
- 18:43method of payment he choose, okay? By
- 18:46using that, we will
- 18:48he will do the payment. Once the payment
- 18:50is done,
- 18:51I will move to the order page, where I
- 18:53will confirm his order.
- 18:56Okay? Then after that, I will move to a
- 18:58kind of notification service, where we
- 19:00will send the order confirmation to the
- 19:03user.
- 19:04Mhm. Yes, correct.
- 19:08Okay.
- 19:10Moving ahead. Can you tell me what
- 19:12happens if two auto configuration
- 19:14classes define the same mean?
- 19:19Define the same mean in the sense can
- 19:20you come again, please?
- 19:21Like there are two auto configuration
- 19:23classes, okay? That has the same mean.
- 19:29And you are
- 19:30yes, yes. Because since they will not I
- 19:33mean we have by using spring boot
- 19:35application rotation we are just doing
- 19:37auto configuration, right?
- 19:38So about two configuration classes have
- 19:41same mean. So I like
- 19:44it will work on which mean it will fetch
- 19:46which mean. So like
- 19:48I'm just asking what do
- 19:50>> Okay, for that one we are having that at
- 19:52the primary at the qualifier annotation.
- 19:54Okay, if you are having multiple same
- 19:56type Before adding that what would
- 19:58happen?
- 20:01If you
- 20:02if you don't add It will throw an error.
- 20:04I just want to know about that error.
- 20:06>> throw an error, yes.
- 20:10So yeah, but spring boot will throw an
- 20:11error. The application won't start.
- 20:14Yep, yep, yep. Spring boot basically
- 20:16will throw an error. It's a bean
- 20:19definition override exception.
- 20:22Okay, you want me to tell the name of
- 20:23that exception? Yep, yep, yep.
- 20:26Okay, yeah it's fine if you
- 20:28Oh no. Okay, so what happens if no
- 20:31active profile is set in the spring
- 20:32boot?
- 20:34So if no active profile setting spring
- 20:36boot, then like
- 20:38by default we'll be having application
- 20:40properties file, right? So it will fetch
- 20:42the data
- 20:43data from that file.
- 20:46If you don't have that file, then spring
- 20:48boot will start giving us
- 20:50errors.
- 20:52Okay.
- 20:53Okay, so tell me what happens if you
- 20:55define two spring data JPA repositories
- 20:57for the same entity?
- 21:03Same entity for
- 21:06two repository for same entity. Mhm.
- 21:10Oh, okay. Okay.
- 21:13Uh,
- 21:14sorry, no idea on this one. All right,
- 21:17it's fine.
- 21:18Uh, it causes bean definition exception.
- 21:23Okay. Okay.
- 21:24Yep, yep. And how can we resolve this
- 21:27bean conflict? Uh, we must use
- 21:29qualifier. Yeah, bean conflict for
- 21:31primary and qualifier.
- 21:33By using this we can resolve bean
- 21:35conflicts there. Yep, yep, yep.
- 21:38Okay, so tell me what happens if you
- 21:40annotate a class with both controller
- 21:43and rest controller annotation?
- 21:48Okay. So,
- 21:51sorry.
- 21:52So, at the rest controller we use like
- 21:54on top of at the rate controller
- 21:56annotation. So, it is a [clears throat]
- 21:57combination of at the rate controller
- 21:58and at the response body. So, if you
- 22:00define at the rate controller and at the
- 22:02rest controller
- 22:04for the same class, I don't think it
- 22:06will create an issue.
- 22:09Uh, it will work as a it will work as a
- 22:12rest controller itself because at the
- 22:14rest controller is on top of the
- 22:16controller.
- 22:18That's correct.
- 22:19Uh, it will be like two controller and
- 22:21one response body.
- 22:23Right? Two controller annotation. Yeah,
- 22:26it will work fine.
- 22:26>> But it will work as a normal at the rate
- 22:28rest controller. Yep, yep. At the rate
- 22:30rest controller.
- 22:33Okay. Yeah.
- 22:35Mhm.
- 22:36>> [clears throat]
- 22:37>> Uh, moving to some
- 22:40uh, core Java
- 22:42uh,
- 22:43uh,
- 22:44uh, I mean things.
- 22:46Uh, can you tell me why uh, is a string
- 22:49immutable in our Java programming
- 22:52language?
- 22:54Yeah,
- 22:55uh, one is a security so that no one can
- 22:58uh, corrupt the data. Another one is
- 23:00memory management because if you are
- 23:02defining a string literals, I assume I
- 23:05define string literal string x1 equal to
- 23:08Java. Okay, so if it is not available in
- 23:11a
- 23:11string pool, so
- 23:13Java will create inside that pool and
- 23:15then in a future if I define string s2
- 23:18equals also Java.
- 23:20Okay, then it won't create Java again.
- 23:22The s2 also will point to the same
- 23:24string.
- 23:25So there is this memory management is
- 23:28there and the security because they know
- 23:30it is not easy to corrupt.
- 23:32So these two are
- 23:34the important reasons for immutability
- 23:36of string. Yep. Yep. Yep.
- 23:39Okay, tell me if you want a mutable
- 23:42version of a string, what would you use?
- 23:45Yeah.
- 23:46Yeah, in string there are two Sorry, in
- 23:49Java there are two possibility for that.
- 23:50One is string builder and the one string
- 23:52buffer. Both will gives us a mutable
- 23:55strings option, but
- 23:57>> [clears throat]
- 23:57>> there is the one difference is string
- 23:59builder is a not thread safe, but string
- 24:00buffer is thread safe.
- 24:02Correct.
- 24:04Um can you tell me how does hash map
- 24:06work internally?
- 24:07Tell me two internal working of hash map
- 24:10before Java 8 and after Java 8.
- 24:14Oh, okay. I'm not sure with that what is
- 24:17before Java 8 and after Java 8, but I
- 24:18know how it works.
- 24:20>> Yep. Yep. Tell me after Java 8.
- 24:21>> Sorry.
- 24:22So whenever we try to
- 24:26save the data in a hash map,
- 24:27>> [clears throat]
- 24:28>> okay, now based on our key, first it
- 24:30will calculate the hash code for that
- 24:32key.
- 24:33Okay, and then it will
- 24:37it will calculate what is the bucket
- 24:39value for that one.
- 24:41Okay, once the calculation is done, the
- 24:43value will goes and sit into that
- 24:45particular bucket.
- 24:54Yeah, is that fine?
- 24:56Sorry, I lost you last 2 minutes.
- 25:02Okay, now I told you
- 25:04Okay, okay. Regarding the hash code
- 25:06>> what about when we are inserting any
- 25:08element, when we are putting any
- 25:10element, where it is getting stored?
- 25:13In a linked list, red black tree, or
- 25:15something like that, do you know?
- 25:18Yeah, yeah. So, whenever is a hash
- 25:19collision happened, right? Hash
- 25:21collision in the sense if multiple keys,
- 25:22you know, pointing to the same bucket.
- 25:24Mhm. Okay? Then uh
- 25:27Uh, Java what we will do is uh
- 25:29that one bucket it will convert into a
- 25:32linked list of size, I guess, eight,
- 25:34okay? So, up to the size eight it will
- 25:37store the values in there. And if it is
- 25:40reached more than eight, then it will
- 25:41convert that linked list to red black
- 25:43tree, and it will start saving that
- 25:46data. Okay, okay.
- 25:48Yes, yes. Uh, that's correct. And the
- 25:50major difference between Java, I mean,
- 25:52prior to Java 8 and after Java 8 is this
- 25:55uh tree. I mean, before Java 8, we just
- 25:58used to store the things in the linked
- 26:00list only. There were no treefication,
- 26:02means converting linked list to tree.
- 26:04>> Oh, okay, okay.
- 26:06>> We have just optimized things after Java
- 26:088.
- 26:10Okay? Okay. Um, can you tell me how does
- 26:13this uh concurrent hash map handle
- 26:15concurrency different than and like we
- 26:18know that it is different than hash map.
- 26:20So, like in what parameters it is
- 26:22different than hash map and how it is
- 26:24uh handling concurrency?
- 26:27Okay, so concurrent hash map handling
- 26:29concurrency based on key value pair,
- 26:31okay? Okay. So, whenever a thread is
- 26:34accessing a particular key value pair,
- 26:36Mhm. okay? Concurrent [clears throat]
- 26:37hash map will set the lock on that
- 26:39particular key value pair only. That
- 26:41means each key value pair will be
- 26:43accessed by one thread at a time. Mhm.
- 26:45The remaining threads can access other
- 26:47key value pairs, but not the locked
- 26:49key value pair, okay? In this case, we
- 26:51can say that each key value pair is
- 26:53getting manipulated by only one thread
- 26:55at a time.
- 26:56Okay? So, that it will maintain the
- 26:58concurrency and thread safe.
- 27:02Okay. Got it. That's correct.
- 27:05Um how does I mean, how are static
- 27:08variables stored in memory compared to
- 27:10the instance variables?
- 27:15Uh okay. So,
- 27:19in a in you are saying like memory save,
- 27:21right? How they are whether it is in
- 27:23stack or heap. Mhm. [clears throat] Yep.
- 27:25Yep.
- 27:27Okay. So, yeah, like static variables
- 27:30are related to class, not objects. Mhm.
- 27:32Uh so,
- 27:34I
- 27:35heap is to
- 27:36to stack.
- 27:38So, I guess
- 27:40those variables will be saved in uh
- 27:43stack I guess, but because heap is used
- 27:44to store the objects. Mhm.
- 27:48So, I guess so because like I'm not sure
- 27:50about the new memory how memory works
- 27:53exactly.
- 27:54Uh okay. No, it's fine. Uh stack
- 27:57variable lives in method area, class
- 27:59loader memory, instance variables in a
- 28:01heap inside objects.
- 28:04Okay? Oh, okay.
- 28:06Yeah.
- 28:07Okay.
- 28:08Uh do you know about the design patterns
- 28:11in Java?
- 28:13Yeah, so yes. Design pattern is used to
- 28:16give a proper solution to a common
- 28:19problems. Mhm. Uh it's not the code. It
- 28:21is the way how you code.
- 28:23Okay. There are different types of
- 28:25design patterns like a creation,
- 28:27structural, and behavior. Okay? So,
- 28:30coming to creation behavior design
- 28:32pattern, these are not what I have used.
- 28:35Okay? They are we are having
- 28:37multiple like builder pattern is there.
- 28:40Mhm. Factory design is there. Abstract
- 28:42factory is there.
- 28:42>> pattern does?
- 28:45Okay. So, I you are having a class and
- 28:47it is having lot of optional variables
- 28:49Mhm. and when you are creating object
- 28:51you want to create the target with only
- 28:53few variables and if you are having only
- 28:56one or two scenarios then you can create
- 28:58only two constructor for that one. But
- 29:00in future if you are getting other
- 29:01requirements and for each requirement
- 29:03you need to create constructor it will
- 29:04be a tedious task. Okay, builder pattern
- 29:07will will resolve this issue. Okay, by
- 29:10using the builder pattern we can create
- 29:12the objects
- 29:13by giving only the fields whichever we
- 29:16wanted. Okay, we don't need to create
- 29:18construct each constructor for each kind
- 29:20of requirement.
- 29:21That's how it resolves that issue.
- 29:24Cool, cool. And
- 29:26what about singleton design pattern?
- 29:29Yeah, so coming to singleton design
- 29:30pattern
- 29:32it will
- 29:34it will say like each class will have
- 29:36only one object at a time.
- 29:38Okay,
- 29:40and that object will be used to in our
- 29:42entire application. Okay.
- 29:45Got it. Can you tell me the difference
- 29:47between lazy singleton implementation
- 29:50and eager singleton implementation?
- 29:56Oh, you lazy singleton eager in
- 29:59Okay, like in Java lazy and eager means
- 30:02whenever we are starting the application
- 30:03during that application itself it will
- 30:05create that object. That is eager.
- 30:08If lazy means whenever we asked for that
- 30:11particular object then only it will get
- 30:13create.
- 30:14Okay. That's correct. So mostly I guess
- 30:16it will be same scenario here also. Same
- 30:18scenario but
- 30:19you you know the implementations of
- 30:21singleton design patterns we have four
- 30:24five implementations like one is enum
- 30:26based implementation of singleton design
- 30:28pattern. Yes, so one is enum and one is
- 30:30by using the
- 30:32Yeah, yeah, yeah. Okay, which one is the
- 30:34best?
- 30:36My enum is the best because the enum by
- 30:40The it's thread safe.
- 30:42Yep, enum is by default thread-safe.
- 30:44Correct. Yeah.
- 30:46Okay. Uh
- 30:48let's say if someone ask you to write
- 30:50the code of singleton design pattern,
- 30:53best way of singleton design pattern.
- 30:56So, what would you write? Let's say enum
- 30:58base or double locking?
- 31:03Uh so,
- 31:06mostly I will prefer to create enum.
- 31:10Okay.
- 31:11Because it will provide us the all the
- 31:14requirement like it will provide us
- 31:16constructor, we can have fields as well.
- 31:18Okay. And if we create enum, we no need
- 31:21to worry about, you know,
- 31:24using the synchronized blocks for
- 31:26creation of object also.
- 31:28Because if you create a normal class
- 31:29object, then
- 31:31in the creation method, we need to use
- 31:33synchronized.
- 31:35But in enum, we should we can avoid that
- 31:37one also.
- 31:40So, I will prefer creating with enum.
- 31:43Yep, yep. Okay.
- 31:46Um have you ever get a chance to design
- 31:49immutable class?
- 31:52Uh so, I haven't created one, but I know
- 31:55what is an immutable class. I can tell
- 31:57you. Yep, yep. Please go on.
- 31:58>> So, immutable class
- 32:00Sorry? Yeah, I go ahead. I'm saying go
- 32:02ahead.
- 32:03Yeah, sir.
- 32:04Yeah. So, when we say a class immutable
- 32:07is whenever you created an object, okay,
- 32:10once you create it, after that
- 32:12it is not able to modify that object.
- 32:14Such kind of classes we can call it as
- 32:16immutable classes. Okay. And to create
- 32:19immutable classes, we need to follow
- 32:21eight steps.
- 32:23So, first
- 32:24Sorry. The first of all, our class
- 32:25should be final. So, that no one should
- 32:28be overridden. Okay. And our all fields
- 32:31should be final and private.
- 32:33Okay.
- 32:34And then we will give we will we should
- 32:37provide only the
- 32:38construct argumented constructor
- 32:40parameter
- 32:42constructor. We should not provide, you
- 32:43know, default constructor. Mhm. And we
- 32:45should not provide setters also. We
- 32:47should provide only getters.
- 32:49So, in that way we can create an
- 32:50immutable class. Yep. Yep. Yep. That's
- 32:52correct.
- 32:53Okay, so Mayur, it's done from my end
- 32:55and yes, it was a very very nice
- 32:57interview.
About this transcript
This page contains the full transcript of Java Spring Boot 5 Yrs Interview Experience [He Answered all] by GenZ Career, generated from the public captions YouTube serves with the video. The transcript has 4,979 words across 883 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.