YouTube2Text

Java Spring Boot 5 Yrs Interview Experience [He Answered all] — Transcript

by GenZ Career · 4,979 words · 883 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Hey guys, today we have Mehboob and he
  2. 0:02is having total 5 years of experience in
  3. 0:04Java Spring Boot and Microservices. And
  4. 0:06guys, those who want to give same
  5. 0:08framework interview, please fill out the
  6. 0:10form below in the description. So, now
  7. 0:11let's get started. Hey, hello Mehboob.
  8. 0:14How are you? Yeah, I'm doing fine. How
  9. 0:16are you? Yes, I'm also good. Shall we
  10. 0:18start? Yeah, sure. Okay. So, Mehboob,
  11. 0:21can you please introduce yourself and
  12. 0:22your recent project in brief? Yeah, so
  13. 0:25my name is Mehboob Jilani. I'm a Java
  14. 0:27back-end developer.
  15. 0:28I'm having a total of 5 years of
  16. 0:30experience in back-end development. And
  17. 0:33my coming to my recent project, it is
  18. 0:35called Rogers Communication. Mhm. Uh
  19. 0:38where we provide internet-based products
  20. 0:40to users like uh
  21. 0:43Wi-Fi, streaming, home security. And
  22. 0:45currently, I am working in home security
  23. 0:47team where we provide, you know,
  24. 0:50security cameras, alert monitoring
  25. 0:53monitoring system to users. Got it. Got
  26. 0:55it.
  27. 0:55>> Yeah, that's it briefly about me. Okay,
  28. 0:58thank you. So, it is based on a Spring
  29. 0:59Boot? Yeah, yes. The back-end systems
  30. 1:02are implemented in Java Spring Boot.
  31. 1:04Java Spring Boot. Okay. So, uh Mehboob,
  32. 1:07let's say your current project is taking
  33. 1:10too long to start because of heavy bean
  34. 1:12initialization, right? So, my question
  35. 1:15is how could you optimize startup time?
  36. 1:18Okay, so if it is taking longer time
  37. 1:22due to bean installation, then
  38. 1:24in Spring Boot, we are having an option
  39. 1:26called at the rate lazy initialization.
  40. 1:28So, when we implement lazy
  41. 1:30initialization,
  42. 1:31um when the Spring Boot boot when the
  43. 1:34Spring Boot application is starting, it
  44. 1:35will inject
  45. 1:36create and inject only those bean which
  46. 1:38are required to start the server. And
  47. 1:40the remaining beans will get created
  48. 1:41injected based on the requirement. So,
  49. 1:43in that way, we can optimize the startup
  50. 1:46time.
  51. 1:47Yep, yep, yep. That's correct. We could
  52. 1:49use lazy initialization, right? Okay,
  53. 1:52moving to the next question. A REST
  54. 1:53endpoint is returning outdated cached
  55. 1:56data instead of fresh data.
  56. 1:58Right? So, my question is how a REST
  57. 2:02endpoint you have created a REST
  58. 2:04endpoint, right? Now, it is returning
  59. 2:06outdated cached data instead of a fresh
  60. 2:09data.
  61. 2:10Okay? So, how would you debug and fix
  62. 2:13this? Okay, so
  63. 2:15if it is a, you know,
  64. 2:17which type of endpoint you is it a get
  65. 2:19or, you know, or is it a post? Uh let's
  66. 2:22assume a get endpoint. Okay, if
  67. 2:25uh it is returning the if get mapping is
  68. 2:27returning, you know, outdated data
  69. 2:30I will try to check whether they have
  70. 2:32implemented with ID with key or not
  71. 2:35because we can implement the caching
  72. 2:37with just using at the rate cacheable.
  73. 2:40But, if you don't implement based on key
  74. 2:42then it won't uh update the data. So, I
  75. 2:45will check whether it is updated with uh
  76. 2:47key or not. If it is updated with key,
  77. 2:50then we will I will check whether
  78. 2:52whenever we are, you know, doing post or
  79. 2:54put operation, whether we are updated
  80. 2:56with a
  81. 2:57uh cache put or not.
  82. 2:59So, that whenever if you use with cache
  83. 3:01put, whenever if there is any kind of
  84. 3:02updation happen, the cache manager will
  85. 3:05automatically update the cache.
  86. 3:07So, in that way we can fix that issue.
  87. 3:10Okay.
  88. 3:11Okay, so and also uh we should look a
  89. 3:16TTL time to live settings, right?
  90. 3:19And as you already told me, cache key.
  91. 3:22That's also correct. And also uh we
  92. 3:25should test these things with cache
  93. 3:27evicted or cache manager, right? Okay.
  94. 3:30Okay, cool. Uh moving ahead, you have
  95. 3:32two Spring Boot microservices. Okay?
  96. 3:35They are communicating via REST
  97. 3:37endpoints.
  98. 3:39Okay? One is working fine as expected.
  99. 3:43Okay? One frequently times out under
  100. 3:46load.
  101. 3:49Okay. Okay. Okay. So, how would you
  102. 3:51handle this situation or scenario?
  103. 3:55So, if you do if it is do going to not
  104. 3:58due to load, I will check whether our
  105. 4:00load balancer is working properly or
  106. 4:02not. If it is, you know, if the entire
  107. 4:04load is
  108. 4:05going to only one server, so it will be
  109. 4:07very difficult for that application to
  110. 4:10work. So, we'll check whether our load
  111. 4:12balancer is working or not. And along
  112. 4:14with that, if our load balancer is
  113. 4:15working fine, then we can check whatever
  114. 4:18the code we have written, we can analyze
  115. 4:20the code. Okay, whether we have
  116. 4:22implemented, you know,
  117. 4:24uh for loops with order of n squared.
  118. 4:26Okay, if we if they are there, then we
  119. 4:29need to optimize them order of
  120. 4:31n for loop so that it won't take long
  121. 4:34longer time.
  122. 4:35Uh we can implement, you know,
  123. 4:37resilience4j for this
  124. 4:39fixing.
  125. 4:40Yep, yep, yep, that's correct. We could
  126. 4:42use resilience4j. And we could use uh
  127. 4:46timeouts like we can tune timeouts,
  128. 4:48right?
  129. 4:49And but yes, your answer is correct.
  130. 4:51Okay. Uh moving ahead,
  131. 4:53um let's say you have an API
  132. 4:57that should be publicly accessible.
  133. 5:00Okay? You have an API that should be
  134. 5:03publicly accessible, but
  135. 5:06another endpoint should require
  136. 5:08authentication. Okay. So, how do you
  137. 5:10configure this in a Spring Security with
  138. 5:13a Spring Boot?
  139. 5:15Yeah. Yes, so in Spring Security when we
  140. 5:17are implementing or overriding a
  141. 5:19security filter chain, we can implement
  142. 5:21them. So,
  143. 5:23during this there is a option called
  144. 5:25permit all and authenticated. So,
  145. 5:27whichever the public endpoints are
  146. 5:28there, so by using the request matcher,
  147. 5:31we can
  148. 5:32give that endpoint and then we can
  149. 5:35do like permit all so that it won't need
  150. 5:37authentication. And for the remaining
  151. 5:39all the other endpoints, it should need
  152. 5:41authentication because we will use
  153. 5:43permit all and then we can use
  154. 5:45authenticated so that all the public
  155. 5:48endpoints don't need authentication.
  156. 5:50Yep, yep, yep. That's correct.
  157. 5:53Okay.
  158. 5:54Hey guys, I want to share something
  159. 5:55important with you. Actually, Mehboob
  160. 5:58prepared from our interview preparation
  161. 5:59kit and cracked multiple interviews. We
  162. 6:02have also referred him to the multiple
  163. 6:04companies. So guys, let me tell you this
  164. 6:06interview preparation kit has four main
  165. 6:08parts. First is complete interview
  166. 6:09preparation material. It is a
  167. 6:11step-by-step material made by me, expert
  168. 6:13in MNCs interviews. 99% of questions
  169. 6:16asked in interviews are covered in it,
  170. 6:18okay? Second is two real enterprise
  171. 6:20client projects. Code and video recorded
  172. 6:22sessions are there and you can add this
  173. 6:24in your resume. Third is lifetime chat
  174. 6:27support. Here you can ask your doubts
  175. 6:29anytime. Fourth is reference support.
  176. 6:31Here we help you to get referred to the
  177. 6:33top MNCs, okay? So basically, the
  178. 6:35material is organized as per your
  179. 6:37experience level and covers Java, Spring
  180. 6:39Boot, Spring Security, Spring Data JPA,
  181. 6:41Microservices, Kafka, Maven, Git, coding
  182. 6:44questions, stream web API coding
  183. 6:45questions, and many more. You can buy
  184. 6:47just a complete interview preparation
  185. 6:49material or the full interview
  186. 6:51preparation kit with project supports
  187. 6:52and references. I have added the links
  188. 6:54in the description below. So now, moving
  189. 6:56to our interview. And guys, before
  190. 6:58moving to our interview, since Mehboob
  191. 7:00is here, so we can ask for a feedback.
  192. 7:02So Mehboob, can you please go ahead?
  193. 7:03Yeah, so I have prepared by using your
  194. 7:06interview preparation kit and it helped
  195. 7:08me a lot. Okay. Actually, I'm able to
  196. 7:11crack my interview, so yeah. Thanks for
  197. 7:13that. Okay, okay. Thank you.
  198. 7:15Moving ahead, guys.
  199. 7:17So Mehboob,
  200. 7:20let's say your application works locally
  201. 7:24but fails to connect to the database in
  202. 7:26production.
  203. 7:28Okay?
  204. 7:29What steps would you take to analyze the
  205. 7:32issue and fix it?
  206. 7:34Okay,
  207. 7:35let me think about it one second.
  208. 7:40Yeah.
  209. 7:41Okay, so when we are working in our
  210. 7:43local right? So, whatever
  211. 7:47the in application of properties,
  212. 7:48whatever the data source credentials we
  213. 7:52have given, we know that it will be
  214. 7:54fine. But when we are going into prod,
  215. 7:57okay? So, most of them we don't get
  216. 7:59hardcoded values. Mostly we will fetch
  217. 8:01it from, you know, from either config
  218. 8:03server or some other profiles. Mhm.
  219. 8:06>> Okay. So, I will check when we are
  220. 8:09defining in the config server whether we
  221. 8:11defined the proper credentials or not.
  222. 8:14Okay.
  223. 8:14>> Okay. Then after that if you are If you
  224. 8:17are fetching If you are using profiles,
  225. 8:20whether we started with the correct
  226. 8:21profile or not. Like we we We can have
  227. 8:23multiple profiles, right? Okay, if it is
  228. 8:26going for prod, the only prod profile
  229. 8:27should be activated. So, I will check
  230. 8:30whether we have activated the prod
  231. 8:32profile or some other profiles.
  232. 8:34So, these two things we can do.
  233. 8:37Uh other things I'm not sure about them.
  234. 8:39Yep, yep, yep. Uh that's correct. And
  235. 8:42other than this, uh we could check SSL
  236. 8:45certificates, connection pool size,
  237. 8:47right? And
  238. 8:49logs as you have already told this,
  239. 8:51okay?
  240. 8:52>> [clears throat]
  241. 8:52>> Now, moving ahead,
  242. 8:54um Mehboob, one of your API takes too
  243. 8:57long because it loads a large data set.
  244. 9:01Okay? Mhm. Yeah. So, how would you
  245. 9:04improve the performance?
  246. 9:07So, if the API is slow due to the large
  247. 9:10data, then we can implement pagination.
  248. 9:12Okay. When we implement [clears throat]
  249. 9:14pagination, so rather So, instead of
  250. 9:18sending the entire data, we can send the
  251. 9:20data in chunks based on the user
  252. 9:21request. Mhm.
  253. 9:23>> Okay. In pagination, there is a
  254. 9:25We will have, you know, what is a page
  255. 9:27size and what is a page number. Mhm.
  256. 9:29>> Based on that, we will fetch only that
  257. 9:31particular data and we will send that
  258. 9:33one. In that way, we can avoid this
  259. 9:35issue.
  260. 9:36Okay, that's correct.
  261. 9:38Moving ahead,
  262. 9:39let's say you have sensitive configs.
  263. 9:42Maybe DB passwords, maybe API keys in
  264. 9:45application properties or application
  265. 9:47YAML, right? So, then my question is how
  266. 9:50would you secure them?
  267. 9:54Okay, so
  268. 9:56in this scenario, it is
  269. 9:59the better way is we won't store actual
  270. 10:03values in our application or properties.
  271. 10:05Mhm.
  272. 10:05>> Okay?
  273. 10:06So, rather than this we will have our
  274. 10:09config server separately, okay? In that
  275. 10:12config server, we will
  276. 10:14store all these kinds of values. And
  277. 10:17whenever we are starting our server, our
  278. 10:19application will fetch those values from
  279. 10:21that config server.
  280. 10:22Mhm. And then it will use to start the
  281. 10:25application.
  282. 10:26So, this is one way. Another one way is
  283. 10:29if you are using K8s to deploy your
  284. 10:32application. Mhm. Inside K8s, we will
  285. 10:35define those variables and we can paste
  286. 10:38the placeholders in our
  287. 10:40application.properties,
  288. 10:41okay? And when we start when we are
  289. 10:44going to start our application so, the
  290. 10:46K8s will map those fields by using
  291. 10:49config maps and it will
  292. 10:52inject those values. So, in that way we
  293. 10:54can
  294. 10:55uh
  295. 10:55protect our values. Mhm. Our properties,
  296. 10:58we can say.
  297. 11:00Okay, cool.
  298. 11:02Moving ahead, a scheduled job in your
  299. 11:05Spring Boot application is running twice
  300. 11:07in production even though you have
  301. 11:10deployed only once.
  302. 11:13What might be happening?
  303. 11:16Okay, so are you saying about a Spring
  304. 11:19Batch processing?
  305. 11:21No, no.
  306. 11:23Scheduled jobs. Yeps.
  307. 11:25Okay, scheduled jobs. Okay, so in that
  308. 11:27case so, I will check in
  309. 11:30by using which
  310. 11:32method I have
  311. 11:34you know, deployed it whether I have
  312. 11:35used I have used a fixed rate or fixed
  313. 11:37delay. Mhm. In this [clears throat]
  314. 11:39scenario, whatever we
  315. 11:41we defined there is a most probably
  316. 11:44there should not be a possibility of,
  317. 11:45you know, executing that job multiple
  318. 11:47times. But if you deploy by using cron
  319. 11:50job, we will give the cron command.
  320. 11:52Okay.
  321. 11:53If there is anything issue in that cron
  322. 11:55command, there is a chance of executing
  323. 11:59that job multiple times. So, I will try
  324. 12:01to fix that cron job.
  325. 12:04And it will fix the issue.
  326. 12:06Yep. Yep. That's correct. And also, one
  327. 12:08more thing I would like to highlight.
  328. 12:10Um we can also check whether multiple
  329. 12:13application instances running.
  330. 12:16Right?
  331. 12:17Or Or multiple schedulers enabled.
  332. 12:20Right?
  333. 12:22And also, what you have already told us.
  334. 12:25Okay?
  335. 12:26Okay.
  336. 12:27Um so, your REST API allows file
  337. 12:31uploads, but user complain about large
  338. 12:35file failing silently.
  339. 12:38Mhm. Okay. So, how would you fix this
  340. 12:41issue?
  341. 12:43So,
  342. 12:45Sorry. Yep. So, in the Spring Boot
  343. 12:49application.properties, we can define
  344. 12:51one
  345. 12:52key value, spring.max-file-upload. Okay?
  346. 12:55So, in-built I think the Spring Boot
  347. 12:58supports 1 MB file. Okay? I guess so.
  348. 13:01I'm not sure. I guess. But if user is
  349. 13:04trying to upload, you know, huge uh size
  350. 13:07file, okay, then we need to
  351. 13:10uh manually define
  352. 13:12to Spring Boot that you can allow this
  353. 13:14much of file size in your
  354. 13:15application.properties. Okay?
  355. 13:18And this way we can fix this issue.
  356. 13:21Yep. Yep. Yep. That's correct. Uh we can
  357. 13:24define our maximum file size or maximum
  358. 13:27request size, right?
  359. 13:28>> Yeah. Uh it could be done like uh
  360. 13:30spring.servlet.multipart
  361. 13:33{hyphen} max {hyphen}
  362. 13:35>> multipart Uh something like that. Okay?
  363. 13:38Yep. Uh moving ahead. After a Spring
  364. 13:41Boot version upgradation
  365. 13:44Okay, after upgrading Spring Boot
  366. 13:46version, your custom bean stopped
  367. 13:49working because a default bean started
  368. 13:52overriding it.
  369. 13:54So, how would you fix this issue?
  370. 13:56>> Okay.
  371. 14:01I don't know.
  372. 14:03Oh, okay. So, like I'm I haven't tried
  373. 14:07this one, okay? But what
  374. 14:09my procedure will be first I will try to
  375. 14:12go through a little bit of documentation
  376. 14:13of that new version,
  377. 14:15and I will try to check whether if any
  378. 14:17of the like whatever I have used when
  379. 14:20the whether any of them is got
  380. 14:21deprecated or not. Okay? If it gets
  381. 14:24deprecated, then I will try to
  382. 14:27uh convert I will try to change them by
  383. 14:29using the whatever the newly updated
  384. 14:31one.
  385. 14:33Uh this is one thing we can do.
  386. 14:35Uh
  387. 14:37Yeah, actually like I'm not sure about
  388. 14:39this like how can we fix it? But
  389. 14:41this is one thing I will do, but Okay.
  390. 14:44Uh
  391. 14:44I think you have already know the
  392. 14:47answers, but let me tell you. Uh we
  393. 14:49could use primary qualifier or disable
  394. 14:51auto configuration.
  395. 14:54Oh, that is for
  396. 14:56uh uh like to
  397. 14:59Okay, which which bean we need to use,
  398. 15:00right? Yeah, yeah. Let's say
  399. 15:02our custom bean stopped working because
  400. 15:04a default bean is started overriding it.
  401. 15:08Right? Uh
  402. 15:09we can disable the default bean by
  403. 15:11excluding or we can make our bean
  404. 15:12primary.
  405. 15:15Yeah, yeah, yeah. I know this plantation
  406. 15:16with that work, but yeah, yeah. Yeah, I
  407. 15:18said it to you already.
  408. 15:21You knew the answers. Okay, moving
  409. 15:23ahead.
  410. 15:24Um your API endpoint returns an empty
  411. 15:27JSON response even though the data the
  412. 15:31DB has data.
  413. 15:33Okay. What would be the possible causes?
  414. 15:38Well, okay, so what in possible causes
  415. 15:42so first thing will be um in most of the
  416. 15:45interface application when we sending
  417. 15:48data to customer, we won't send the
  418. 15:49entire data. We will use DTOs and we
  419. 15:51will send only the required data to
  420. 15:53user. Okay.
  421. 15:55>> Mhm. And we will map the we will map
  422. 15:57them by using the actual data from DB
  423. 15:58and we will send it to user. I will
  424. 16:00check whether during the mapping
  425. 16:02whatever the fields we are sending to
  426. 16:04user, okay, whether they are getting
  427. 16:06actual data from DB or they they are
  428. 16:09getting set with null. That's one thing
  429. 16:10I can do.
  430. 16:12And
  431. 16:13another thing I can check
  432. 16:15in our DTO files whatever the
  433. 16:17annotations I have mentioned, there is
  434. 16:19an annotation called, you know, JSON
  435. 16:20include nonnull. In sometimes, even the
  436. 16:23JSON itself it will exclude some fields
  437. 16:26if it didn't find the value.
  438. 16:28So I can check whether it is working as
  439. 16:30expected or not.
  440. 16:32Okay. Cool.
  441. 16:34Um so yes, that is correct and we could
  442. 16:37also check Jackson serialization issues.
  443. 16:41Missing getters. That's a basic one. I
  444. 16:43mean
  445. 16:45Yep, yep. Uh moving ahead.
  446. 16:47Um in your system, uh you have 10 Spring
  447. 16:50Boot microservices, right?
  448. 16:53And managing configurations like um DB
  449. 16:56URLs, feature flags, etc. separately has
  450. 17:00become painful.
  451. 17:02You got it?
  452. 17:04Yeah.
  453. 17:04>> So how how would you handle centralized
  454. 17:06configuration management?
  455. 17:10Yeah, so
  456. 17:11sorry.
  457. 17:12So I will implement one
  458. 17:14particular service as a config server.
  459. 17:17okay? That config server will have all
  460. 17:19the
  461. 17:20DB configuration, all the required
  462. 17:22properties
  463. 17:24as per our requirement, okay? And none
  464. 17:26of other applications will have those.
  465. 17:28And I will use that beans. And our
  466. 17:31application, whenever they need to
  467. 17:33start, they will fetch those values from
  468. 17:35the config server only. In that way,
  469. 17:37whenever we need to update or we need to
  470. 17:39change any kind of fields, we can
  471. 17:41able to go and change in only one one
  472. 17:44application rather than
  473. 17:45updating in all the 10 servers.
  474. 17:49Yep. Yep. Yep. That's correct.
  475. 17:52Okay.
  476. 17:53So, can you tell me how would you design
  477. 17:56the checkout process for an e-commerce
  478. 17:58platform?
  479. 18:00Right, like cart, payment, order,
  480. 18:02inventory update by using Spring Boot
  481. 18:04microservices.
  482. 18:08Just answer me brief.
  483. 18:10You don't have to answer it
  484. 18:12with too much details. Yeah, so yeah, so
  485. 18:15first of all, user
  486. 18:17will logs into
  487. 18:19e-commerce application.
  488. 18:22Then first of all, he will add the item
  489. 18:24to cart, okay? Then cart operation will
  490. 18:26get performed, and he will able to see
  491. 18:28all his product details in the cart.
  492. 18:30Then he will go to the
  493. 18:32payment options, okay?
  494. 18:35There
  495. 18:36we will implement our payment service
  496. 18:39separately, okay? And then wherever
  497. 18:42whatever
  498. 18:43method of payment he choose, okay? By
  499. 18:46using that, we will
  500. 18:48he will do the payment. Once the payment
  501. 18:50is done,
  502. 18:51I will move to the order page, where I
  503. 18:53will confirm his order.
  504. 18:56Okay? Then after that, I will move to a
  505. 18:58kind of notification service, where we
  506. 19:00will send the order confirmation to the
  507. 19:03user.
  508. 19:04Mhm. Yes, correct.
  509. 19:08Okay.
  510. 19:10Moving ahead. Can you tell me what
  511. 19:12happens if two auto configuration
  512. 19:14classes define the same mean?
  513. 19:19Define the same mean in the sense can
  514. 19:20you come again, please?
  515. 19:21Like there are two auto configuration
  516. 19:23classes, okay? That has the same mean.
  517. 19:29And you are
  518. 19:30yes, yes. Because since they will not I
  519. 19:33mean we have by using spring boot
  520. 19:35application rotation we are just doing
  521. 19:37auto configuration, right?
  522. 19:38So about two configuration classes have
  523. 19:41same mean. So I like
  524. 19:44it will work on which mean it will fetch
  525. 19:46which mean. So like
  526. 19:48I'm just asking what do
  527. 19:50>> Okay, for that one we are having that at
  528. 19:52the primary at the qualifier annotation.
  529. 19:54Okay, if you are having multiple same
  530. 19:56type Before adding that what would
  531. 19:58happen?
  532. 20:01If you
  533. 20:02if you don't add It will throw an error.
  534. 20:04I just want to know about that error.
  535. 20:06>> throw an error, yes.
  536. 20:10So yeah, but spring boot will throw an
  537. 20:11error. The application won't start.
  538. 20:14Yep, yep, yep. Spring boot basically
  539. 20:16will throw an error. It's a bean
  540. 20:19definition override exception.
  541. 20:22Okay, you want me to tell the name of
  542. 20:23that exception? Yep, yep, yep.
  543. 20:26Okay, yeah it's fine if you
  544. 20:28Oh no. Okay, so what happens if no
  545. 20:31active profile is set in the spring
  546. 20:32boot?
  547. 20:34So if no active profile setting spring
  548. 20:36boot, then like
  549. 20:38by default we'll be having application
  550. 20:40properties file, right? So it will fetch
  551. 20:42the data
  552. 20:43data from that file.
  553. 20:46If you don't have that file, then spring
  554. 20:48boot will start giving us
  555. 20:50errors.
  556. 20:52Okay.
  557. 20:53Okay, so tell me what happens if you
  558. 20:55define two spring data JPA repositories
  559. 20:57for the same entity?
  560. 21:03Same entity for
  561. 21:06two repository for same entity. Mhm.
  562. 21:10Oh, okay. Okay.
  563. 21:13Uh,
  564. 21:14sorry, no idea on this one. All right,
  565. 21:17it's fine.
  566. 21:18Uh, it causes bean definition exception.
  567. 21:23Okay. Okay.
  568. 21:24Yep, yep. And how can we resolve this
  569. 21:27bean conflict? Uh, we must use
  570. 21:29qualifier. Yeah, bean conflict for
  571. 21:31primary and qualifier.
  572. 21:33By using this we can resolve bean
  573. 21:35conflicts there. Yep, yep, yep.
  574. 21:38Okay, so tell me what happens if you
  575. 21:40annotate a class with both controller
  576. 21:43and rest controller annotation?
  577. 21:48Okay. So,
  578. 21:51sorry.
  579. 21:52So, at the rest controller we use like
  580. 21:54on top of at the rate controller
  581. 21:56annotation. So, it is a [clears throat]
  582. 21:57combination of at the rate controller
  583. 21:58and at the response body. So, if you
  584. 22:00define at the rate controller and at the
  585. 22:02rest controller
  586. 22:04for the same class, I don't think it
  587. 22:06will create an issue.
  588. 22:09Uh, it will work as a it will work as a
  589. 22:12rest controller itself because at the
  590. 22:14rest controller is on top of the
  591. 22:16controller.
  592. 22:18That's correct.
  593. 22:19Uh, it will be like two controller and
  594. 22:21one response body.
  595. 22:23Right? Two controller annotation. Yeah,
  596. 22:26it will work fine.
  597. 22:26>> But it will work as a normal at the rate
  598. 22:28rest controller. Yep, yep. At the rate
  599. 22:30rest controller.
  600. 22:33Okay. Yeah.
  601. 22:35Mhm.
  602. 22:36>> [clears throat]
  603. 22:37>> Uh, moving to some
  604. 22:40uh, core Java
  605. 22:42uh,
  606. 22:43uh,
  607. 22:44uh, I mean things.
  608. 22:46Uh, can you tell me why uh, is a string
  609. 22:49immutable in our Java programming
  610. 22:52language?
  611. 22:54Yeah,
  612. 22:55uh, one is a security so that no one can
  613. 22:58uh, corrupt the data. Another one is
  614. 23:00memory management because if you are
  615. 23:02defining a string literals, I assume I
  616. 23:05define string literal string x1 equal to
  617. 23:08Java. Okay, so if it is not available in
  618. 23:11a
  619. 23:11string pool, so
  620. 23:13Java will create inside that pool and
  621. 23:15then in a future if I define string s2
  622. 23:18equals also Java.
  623. 23:20Okay, then it won't create Java again.
  624. 23:22The s2 also will point to the same
  625. 23:24string.
  626. 23:25So there is this memory management is
  627. 23:28there and the security because they know
  628. 23:30it is not easy to corrupt.
  629. 23:32So these two are
  630. 23:34the important reasons for immutability
  631. 23:36of string. Yep. Yep. Yep.
  632. 23:39Okay, tell me if you want a mutable
  633. 23:42version of a string, what would you use?
  634. 23:45Yeah.
  635. 23:46Yeah, in string there are two Sorry, in
  636. 23:49Java there are two possibility for that.
  637. 23:50One is string builder and the one string
  638. 23:52buffer. Both will gives us a mutable
  639. 23:55strings option, but
  640. 23:57>> [clears throat]
  641. 23:57>> there is the one difference is string
  642. 23:59builder is a not thread safe, but string
  643. 24:00buffer is thread safe.
  644. 24:02Correct.
  645. 24:04Um can you tell me how does hash map
  646. 24:06work internally?
  647. 24:07Tell me two internal working of hash map
  648. 24:10before Java 8 and after Java 8.
  649. 24:14Oh, okay. I'm not sure with that what is
  650. 24:17before Java 8 and after Java 8, but I
  651. 24:18know how it works.
  652. 24:20>> Yep. Yep. Tell me after Java 8.
  653. 24:21>> Sorry.
  654. 24:22So whenever we try to
  655. 24:26save the data in a hash map,
  656. 24:27>> [clears throat]
  657. 24:28>> okay, now based on our key, first it
  658. 24:30will calculate the hash code for that
  659. 24:32key.
  660. 24:33Okay, and then it will
  661. 24:37it will calculate what is the bucket
  662. 24:39value for that one.
  663. 24:41Okay, once the calculation is done, the
  664. 24:43value will goes and sit into that
  665. 24:45particular bucket.
  666. 24:54Yeah, is that fine?
  667. 24:56Sorry, I lost you last 2 minutes.
  668. 25:02Okay, now I told you
  669. 25:04Okay, okay. Regarding the hash code
  670. 25:06>> what about when we are inserting any
  671. 25:08element, when we are putting any
  672. 25:10element, where it is getting stored?
  673. 25:13In a linked list, red black tree, or
  674. 25:15something like that, do you know?
  675. 25:18Yeah, yeah. So, whenever is a hash
  676. 25:19collision happened, right? Hash
  677. 25:21collision in the sense if multiple keys,
  678. 25:22you know, pointing to the same bucket.
  679. 25:24Mhm. Okay? Then uh
  680. 25:27Uh, Java what we will do is uh
  681. 25:29that one bucket it will convert into a
  682. 25:32linked list of size, I guess, eight,
  683. 25:34okay? So, up to the size eight it will
  684. 25:37store the values in there. And if it is
  685. 25:40reached more than eight, then it will
  686. 25:41convert that linked list to red black
  687. 25:43tree, and it will start saving that
  688. 25:46data. Okay, okay.
  689. 25:48Yes, yes. Uh, that's correct. And the
  690. 25:50major difference between Java, I mean,
  691. 25:52prior to Java 8 and after Java 8 is this
  692. 25:55uh tree. I mean, before Java 8, we just
  693. 25:58used to store the things in the linked
  694. 26:00list only. There were no treefication,
  695. 26:02means converting linked list to tree.
  696. 26:04>> Oh, okay, okay.
  697. 26:06>> We have just optimized things after Java
  698. 26:088.
  699. 26:10Okay? Okay. Um, can you tell me how does
  700. 26:13this uh concurrent hash map handle
  701. 26:15concurrency different than and like we
  702. 26:18know that it is different than hash map.
  703. 26:20So, like in what parameters it is
  704. 26:22different than hash map and how it is
  705. 26:24uh handling concurrency?
  706. 26:27Okay, so concurrent hash map handling
  707. 26:29concurrency based on key value pair,
  708. 26:31okay? Okay. So, whenever a thread is
  709. 26:34accessing a particular key value pair,
  710. 26:36Mhm. okay? Concurrent [clears throat]
  711. 26:37hash map will set the lock on that
  712. 26:39particular key value pair only. That
  713. 26:41means each key value pair will be
  714. 26:43accessed by one thread at a time. Mhm.
  715. 26:45The remaining threads can access other
  716. 26:47key value pairs, but not the locked
  717. 26:49key value pair, okay? In this case, we
  718. 26:51can say that each key value pair is
  719. 26:53getting manipulated by only one thread
  720. 26:55at a time.
  721. 26:56Okay? So, that it will maintain the
  722. 26:58concurrency and thread safe.
  723. 27:02Okay. Got it. That's correct.
  724. 27:05Um how does I mean, how are static
  725. 27:08variables stored in memory compared to
  726. 27:10the instance variables?
  727. 27:15Uh okay. So,
  728. 27:19in a in you are saying like memory save,
  729. 27:21right? How they are whether it is in
  730. 27:23stack or heap. Mhm. [clears throat] Yep.
  731. 27:25Yep.
  732. 27:27Okay. So, yeah, like static variables
  733. 27:30are related to class, not objects. Mhm.
  734. 27:32Uh so,
  735. 27:34I
  736. 27:35heap is to
  737. 27:36to stack.
  738. 27:38So, I guess
  739. 27:40those variables will be saved in uh
  740. 27:43stack I guess, but because heap is used
  741. 27:44to store the objects. Mhm.
  742. 27:48So, I guess so because like I'm not sure
  743. 27:50about the new memory how memory works
  744. 27:53exactly.
  745. 27:54Uh okay. No, it's fine. Uh stack
  746. 27:57variable lives in method area, class
  747. 27:59loader memory, instance variables in a
  748. 28:01heap inside objects.
  749. 28:04Okay? Oh, okay.
  750. 28:06Yeah.
  751. 28:07Okay.
  752. 28:08Uh do you know about the design patterns
  753. 28:11in Java?
  754. 28:13Yeah, so yes. Design pattern is used to
  755. 28:16give a proper solution to a common
  756. 28:19problems. Mhm. Uh it's not the code. It
  757. 28:21is the way how you code.
  758. 28:23Okay. There are different types of
  759. 28:25design patterns like a creation,
  760. 28:27structural, and behavior. Okay? So,
  761. 28:30coming to creation behavior design
  762. 28:32pattern, these are not what I have used.
  763. 28:35Okay? They are we are having
  764. 28:37multiple like builder pattern is there.
  765. 28:40Mhm. Factory design is there. Abstract
  766. 28:42factory is there.
  767. 28:42>> pattern does?
  768. 28:45Okay. So, I you are having a class and
  769. 28:47it is having lot of optional variables
  770. 28:49Mhm. and when you are creating object
  771. 28:51you want to create the target with only
  772. 28:53few variables and if you are having only
  773. 28:56one or two scenarios then you can create
  774. 28:58only two constructor for that one. But
  775. 29:00in future if you are getting other
  776. 29:01requirements and for each requirement
  777. 29:03you need to create constructor it will
  778. 29:04be a tedious task. Okay, builder pattern
  779. 29:07will will resolve this issue. Okay, by
  780. 29:10using the builder pattern we can create
  781. 29:12the objects
  782. 29:13by giving only the fields whichever we
  783. 29:16wanted. Okay, we don't need to create
  784. 29:18construct each constructor for each kind
  785. 29:20of requirement.
  786. 29:21That's how it resolves that issue.
  787. 29:24Cool, cool. And
  788. 29:26what about singleton design pattern?
  789. 29:29Yeah, so coming to singleton design
  790. 29:30pattern
  791. 29:32it will
  792. 29:34it will say like each class will have
  793. 29:36only one object at a time.
  794. 29:38Okay,
  795. 29:40and that object will be used to in our
  796. 29:42entire application. Okay.
  797. 29:45Got it. Can you tell me the difference
  798. 29:47between lazy singleton implementation
  799. 29:50and eager singleton implementation?
  800. 29:56Oh, you lazy singleton eager in
  801. 29:59Okay, like in Java lazy and eager means
  802. 30:02whenever we are starting the application
  803. 30:03during that application itself it will
  804. 30:05create that object. That is eager.
  805. 30:08If lazy means whenever we asked for that
  806. 30:11particular object then only it will get
  807. 30:13create.
  808. 30:14Okay. That's correct. So mostly I guess
  809. 30:16it will be same scenario here also. Same
  810. 30:18scenario but
  811. 30:19you you know the implementations of
  812. 30:21singleton design patterns we have four
  813. 30:24five implementations like one is enum
  814. 30:26based implementation of singleton design
  815. 30:28pattern. Yes, so one is enum and one is
  816. 30:30by using the
  817. 30:32Yeah, yeah, yeah. Okay, which one is the
  818. 30:34best?
  819. 30:36My enum is the best because the enum by
  820. 30:40The it's thread safe.
  821. 30:42Yep, enum is by default thread-safe.
  822. 30:44Correct. Yeah.
  823. 30:46Okay. Uh
  824. 30:48let's say if someone ask you to write
  825. 30:50the code of singleton design pattern,
  826. 30:53best way of singleton design pattern.
  827. 30:56So, what would you write? Let's say enum
  828. 30:58base or double locking?
  829. 31:03Uh so,
  830. 31:06mostly I will prefer to create enum.
  831. 31:10Okay.
  832. 31:11Because it will provide us the all the
  833. 31:14requirement like it will provide us
  834. 31:16constructor, we can have fields as well.
  835. 31:18Okay. And if we create enum, we no need
  836. 31:21to worry about, you know,
  837. 31:24using the synchronized blocks for
  838. 31:26creation of object also.
  839. 31:28Because if you create a normal class
  840. 31:29object, then
  841. 31:31in the creation method, we need to use
  842. 31:33synchronized.
  843. 31:35But in enum, we should we can avoid that
  844. 31:37one also.
  845. 31:40So, I will prefer creating with enum.
  846. 31:43Yep, yep. Okay.
  847. 31:46Um have you ever get a chance to design
  848. 31:49immutable class?
  849. 31:52Uh so, I haven't created one, but I know
  850. 31:55what is an immutable class. I can tell
  851. 31:57you. Yep, yep. Please go on.
  852. 31:58>> So, immutable class
  853. 32:00Sorry? Yeah, I go ahead. I'm saying go
  854. 32:02ahead.
  855. 32:03Yeah, sir.
  856. 32:04Yeah. So, when we say a class immutable
  857. 32:07is whenever you created an object, okay,
  858. 32:10once you create it, after that
  859. 32:12it is not able to modify that object.
  860. 32:14Such kind of classes we can call it as
  861. 32:16immutable classes. Okay. And to create
  862. 32:19immutable classes, we need to follow
  863. 32:21eight steps.
  864. 32:23So, first
  865. 32:24Sorry. The first of all, our class
  866. 32:25should be final. So, that no one should
  867. 32:28be overridden. Okay. And our all fields
  868. 32:31should be final and private.
  869. 32:33Okay.
  870. 32:34And then we will give we will we should
  871. 32:37provide only the
  872. 32:38construct argumented constructor
  873. 32:40parameter
  874. 32:42constructor. We should not provide, you
  875. 32:43know, default constructor. Mhm. And we
  876. 32:45should not provide setters also. We
  877. 32:47should provide only getters.
  878. 32:49So, in that way we can create an
  879. 32:50immutable class. Yep. Yep. Yep. That's
  880. 32:52correct.
  881. 32:53Okay, so Mayur, it's done from my end
  882. 32:55and yes, it was a very very nice
  883. 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.