Top 10 Java Interview Questions for 10+ years experience — Transcript
Full transcript
- 0:00Hello, friends. Based on my overall 15
- 0:03plus years of experience, today I'm
- 0:05going to share the top 10 Java interview
- 0:09questions that I feel are very important
- 0:11for senior candidates. Some of these
- 0:14questions are also scenario-based. So,
- 0:16without wasting time, let's start with
- 0:19the first question.
- 0:21Explain the concept of item potence in
- 0:24restful API. And in my In this This is
- 0:27not a very important question, but some
- 0:29students say is that they have been
- 0:31asked in interview, so let's understand
- 0:33it.
- 0:34Uh item potent is a Sorry for my
- 0:36pronunciation. It's item potent or item
- 0:38potent, I don't know.
- 0:40So, item potent is a concept that
- 0:43guarantees that performing the same
- 0:45operation multiple times will always
- 0:49give the same output, same response,
- 0:51same result. Okay? So, the word is hard,
- 0:55but the purpose meaning is easy, okay?
- 0:58For example, see here.
- 1:00See, if you send this get method request
- 1:03100 times again and again, the result
- 1:06will always be the same, okay? You will
- 1:08get the response with the 100
- 1:10the users list, right? Same result. Now,
- 1:14similar to get, we have the put and
- 1:17delete methods also. Those are also item
- 1:19potent. Okay?
- 1:21Now, put put because if you send to
- 1:24update the same request body again and
- 1:26again, so every time the same
- 1:28replacement will happen, and the result
- 1:31will be same.
- 1:33So, that is item potent. Now, what is
- 1:36non-item potent methods? For example,
- 1:38this post method.
- 1:40Because if you send multiple post
- 1:43request with the same request body, then
- 1:46each time a new user new user with a new
- 1:49user ID will be created in the database,
- 1:51right?
- 1:53That means the result has been changed.
- 1:55It is impacted. and it every time it
- 1:59will impact. It's different. Okay?
- 2:02Great. That is the explanation of this
- 2:05concept, and the same thing is written
- 2:08here also, which I already explained,
- 2:10right?
- 2:12All right, my friend. Before moving to
- 2:14the next question, I have a challenge
- 2:17for you.
- 2:18If you are giving interviews, or you are
- 2:20planning to give interviews in future,
- 2:23then [snorts] you will face many
- 2:25obstacles, rejections, especially if you
- 2:28have more experience. But, there is only
- 2:32one key of interview success, and that
- 2:35is never ever give up. So, keep giving
- 2:38interviews, and accept my never give up
- 2:42challenge by typing never give up in the
- 2:45comments right now.
- 2:48And that day you crack your interview,
- 2:52come back and share your success a story
- 2:56in any of my video, like these students
- 3:00have [snorts]
- 3:01shared who got excellent salary hikes by
- 3:05following the never give up mantra.
- 3:08I will repost your success story, and
- 3:13to inspire others also. So, type never
- 3:16give up in the comments now. Let's
- 3:20continue.
- 3:21What is token-based authentication and
- 3:24JWT authentication?
- 3:26Nowadays, this is the most popular kind
- 3:28of authentication technique used in REST
- 3:31APIs.
- 3:33Here, token-based authentication is a
- 3:35type of authentication,
- 3:38and when we use JWT as the token in
- 3:41token-based authentication, then that is
- 3:45JWT authentication. And you can also say
- 3:48like JWT authentication is a type of uh
- 3:51token-based authentication, also, okay?
- 3:53So, JWT stands for JSON Web Token.
- 3:58For interviews, this JWT authentication
- 4:01process is very, very important, and
- 4:04that I'm going to explain here.
- 4:06And here are first the main players in
- 4:08the authentication process.
- 4:10First is our browser, which will act as
- 4:13the front end. You can say also front
- 4:16end you can think of it. And then we
- 4:18have the REST API,
- 4:20which you can also call middleware,
- 4:22server side, back end, okay?
- 4:25Now, there are eight steps in this
- 4:27authentication process of JWT.
- 4:31First, user will
- 4:33from the client side send the username
- 4:36and password through the browser and
- 4:39send them to the API with a post
- 4:41request.
- 4:43Now, of course, I'm not saying that
- 4:44browser will send to the client and
- 4:46client will send to the server.
- 4:48Basically,
- 4:50both will together will send to the API
- 4:52[clears throat] server, okay?
- 4:55Then, in the second step, the API will
- 4:59receive these credentials, right? And
- 5:01they or they will authenticate, or you
- 5:04can say validate those username and
- 5:06password, whether it is valid or not.
- 5:10If credentials are valid, a JWT token
- 5:14will be created, and that will be sent
- 5:17back to the client as a response.
- 5:21Clear?
- 5:22Now, if the credentials are not valid,
- 5:24it will not return uh API server will
- 5:26not return
- 5:27uh and uh JWT token, rather a
- 5:31authentication error will be returned.
- 5:34Then, as a next uh step, the client will
- 5:37store this JWT token in the local
- 5:40storage or in the cookies of the
- 5:42browser, uh okay?
- 5:45Now, listen carefully.
- 5:47When the JWT token is stored, then for
- 5:51every future or subsequent request for
- 5:54the data from client, this token will be
- 5:58sent in the header of every request to
- 6:02the REST API from the client.
- 6:05Okay?
- 6:06Got my point? Token will go every time.
- 6:09Username and
- 6:11password are will not go then.
- 6:13So, now when the API will receive the
- 6:17token, it will check and validate the
- 6:19token signature with the help of some
- 6:21algorithm. And if the token is valid, it
- 6:26must Valid means it must be the same JWT
- 6:29token which
- 6:30initially the API has sent to the
- 6:32client, okay?
- 6:34And if it is valid, then only the API
- 6:37will send the data to the client.
- 6:40Great. Finally, the client will display
- 6:42the data in the browser, and that is the
- 6:45whole process which I make simpler for
- 6:48you.
- 6:49And that's the reason why for any
- 6:51website we have to enter username
- 6:53password only once because uh first time
- 6:58after first time, you will receive the
- 7:00token, and then only the token will be
- 7:02sent for the validation, not the
- 7:04username and password again and again,
- 7:06okay?
- 7:07So, this is the working of JWT token
- 7:10authentication.
- 7:12And yes, there are other authentication
- 7:14techniques also, but this is the most
- 7:17popular one, and that is the answer to
- 7:20this question, the steps and the
- 7:22explanation. Okay?
- 7:25What is dependency injection? How to
- 7:28implement it? Now, very, very important
- 7:30question, and I mark this question with
- 7:33two very important signs because this is
- 7:36asked almost in every interview. And
- 7:38today we will understand it completely.
- 7:41Let me first show you the diagram for
- 7:42the dependency injection implementation,
- 7:44okay?
- 7:45See, normally the dependent class and
- 7:48dependency class are tightly coupled
- 7:50like this. Okay?
- 7:53Here, we directly create the object of
- 7:55the dependency class in this dependent
- 7:58class.
- 7:59You already know that.
- 8:00Now, to replace this math student class
- 8:03with the science student class, we have
- 8:05to change the code of this school class
- 8:08itself.
- 8:09Right?
- 8:10So, this is the example without
- 8:13dependency injection.
- 8:15Okay? But, when we will use dependency
- 8:18injection, then dependency class and
- 8:21dependent classes are loosely coupled
- 8:24and not dependent on each other like
- 8:27this.
- 8:28Here, the object of the dependency class
- 8:31will not create be created inside school
- 8:34class,
- 8:34but will be created and managed inside
- 8:37the Spring IOC container via the
- 8:41appconfig.java
- 8:43file.
- 8:44Okay?
- 8:45Then, you have to create the student
- 8:47interface, which is implement by both
- 8:50math student and science student
- 8:52classes.
- 8:54Okay?
- 8:55Now, listen carefully.
- 8:57Instead of creating the object of
- 8:59dependency classes in the dependent
- 9:01class,
- 9:02you will inject the
- 9:04instance of the student interface into
- 9:07the dependent class via the school class
- 9:10constructor like this.
- 9:13Now, you may ask student interface
- 9:16instance will carry which instance, math
- 9:19student or science student? The answer
- 9:21is
- 9:22whatever instance you will configure in
- 9:25this app.config,
- 9:27that instance will be created and
- 9:28received by the student interface.
- 9:32That's it.
- 9:34See, here if you want to replace the
- 9:36math student with science student in
- 9:38your school class, then change the app
- 9:41config for science student object uh
- 9:44object creation,
- 9:45but you need not to change any any code
- 9:49in the school class.
- 9:51Right? That was the purpose, okay? Do
- 9:54not change the school class.
- 9:56Just changing just change by changing
- 9:58the container
- 10:00and the many classes or controller like
- 10:03you do not have to change all the
- 10:05controller or classes like a school
- 10:07class, okay?
- 10:09Great. That is the example and benefit
- 10:11of dependency injection.
- 10:13And one more learning we had,
- 10:15dependency injection implementation, you
- 10:18have to code for to the interface, not
- 10:22the implementation that dependency
- 10:24classes, okay?
- 10:26Also, you realize that how inversion of
- 10:28control principle is implemented by
- 10:31changing the place of object creation
- 10:34from the class to the container, okay?
- 10:38All right. Finally, here is the simplest
- 10:40definition of dependency injection.
- 10:43Dependency injection is a design pattern
- 10:46that is used to implement the inversion
- 10:49of control principle in Java.
- 10:52Great. The definition diagram are here
- 10:55because I remember how I had a very hard
- 10:58time remembering and revising these this
- 11:01dependency injection concept for my
- 11:03interviews.
- 11:05So, that's why all is here.
- 11:07Now, in the upcoming question, I will
- 11:08show you the code implementation.
- 11:12All right. Before we move forward, here
- 11:14is a small notification.
- 11:17If you don't want to miss anything and
- 11:19want to cover top 350 plus Java
- 11:23interview questions,
- 11:25then I have a full Java interview
- 11:28course.
- 11:29Here is the complete Java interview road
- 11:32map, and in this course, I have covered
- 11:35all the interview questions on all the
- 11:38Java topics.
- 11:40And that is also in a step-by-step
- 11:42manner, so that even if you are new to
- 11:45Java, you still you will understand
- 11:48every every concept.
- 11:51Along with this video course, you will
- 11:53also receive Java interview PDF book for
- 11:57your quick revision.
- 12:00Many senior developers have already
- 12:02cracked their interviews using my
- 12:05interview preparation content. You could
- 12:07be the next one. So, if you are
- 12:10interested in the course or book, then
- 12:14check out the link in the description of
- 12:18this video.
- 12:19Now, let's continue.
- 12:22When to use which type of dependency
- 12:24injection? This I already explained in
- 12:27the previous question, but here I'm
- 12:30writing it all here. Okay? First,
- 12:33constructor injection is used for
- 12:35mandatory dependencies, and this is the
- 12:38most popular one. Second, setter
- 12:41injection is used for injecting optional
- 12:43dependencies.
- 12:45Okay? Third, field injection is there,
- 12:49but it is not good as it has testing
- 12:52limitations. Okay? And last, method
- 12:55injection is used for injecting
- 12:58dependencies dynamically or
- 13:00conditionally.
- 13:02All information written here so that
- 13:04your interview revision will be faster
- 13:07and quickly faster from the book, and
- 13:10you do not forget any of these points in
- 13:13your interviews.
- 13:15When to use singleton scope? What are
- 13:18its its pros and cons?
- 13:20Here is the singleton scope, which I
- 13:22already explained in the previous
- 13:24question.
- 13:25The top advantage of using singleton
- 13:27scope is performance,
- 13:29okay? Because a single bean instance
- 13:32created once only and it is reused
- 13:35multiple times in multiple modules and
- 13:39in multiple requests of your
- 13:41applications, okay? Right? So, this will
- 13:45basically reduce the object creation
- 13:47again and again, which is very good for
- 13:50performance. The same thing is written
- 13:52here.
- 13:53Then the disadvantage is that
- 13:56single beans are shared across multiple
- 13:59threads, okay? In a multi-threaded
- 14:01application. So, like they are shared in
- 14:04multiple requests, okay? So, in a
- 14:08multi-threaded case, the single bean
- 14:10instance can be incorrectly manipulated
- 14:13or it's not good for multiple threads
- 14:15because it will change the information,
- 14:18which is dangerous dangerous for your
- 14:20application functionality, okay?
- 14:22Therefore, for multi-threaded
- 14:24application, single scope singleton
- 14:26scope is not recommended, okay? Same is
- 14:29written here.
- 14:31Finally, the use of singleton scope is
- 14:33it is good for stateless based
- 14:36application because when your request do
- 14:39not maintain or store state or data or
- 14:43session, then sharing instances via
- 14:46singleton scope is never a problem,
- 14:49okay? So, then you you have to use it.
- 14:53So, in the case of rest services, it's
- 14:56the best singleton, okay? So, that is
- 14:58the best answer to this question.
- 15:01What are circular dependencies? How does
- 15:05Spring handle it?
- 15:07First of all, what is circular
- 15:09dependency? Here is a diagram. See, if
- 15:12in your application, if you have two
- 15:14services or classes like service A and
- 15:17service B. Now, suppose service A
- 15:19depends on service B. That means you
- 15:22will inject service B into service A,
- 15:25right?
- 15:26But then,
- 15:27due to some requirement or something,
- 15:29you also
- 15:30want that service B also depends on
- 15:33service A or class A, you can say.
- 15:36So, that this is circular dependency,
- 15:39okay? Here you will use constructor
- 15:41injection, for example, in your service
- 15:44A
- 15:44to inject the service B, and then you
- 15:47will use
- 15:48use constructor injection in service B
- 15:51class to inject service A.
- 15:54So,
- 15:55if you will do that, you will get the
- 15:56error that being currently some creation
- 15:59exception error, that some some error,
- 16:01okay? But because then a spring cannot
- 16:04resolve the dependencies because both
- 16:07class A and class B require each other
- 16:09to be instantiated at the same time,
- 16:13which can't be done at the same time as
- 16:15as I said.
- 16:17Now, in order to solve this problem,
- 16:19there are two ways.
- 16:21If your classes are dependent on each
- 16:23other, then either use setter injection
- 16:26or you can use lazy annotation.
- 16:30Okay? Because setter injection will not
- 16:33immediately instantiate the dependency.
- 16:37As per setter injection, the dependency
- 16:39will be instantiated only when the
- 16:42setter method is called. Right? So, you
- 16:46have to manage in the code that calling
- 16:48the set setter methods of service A and
- 16:51B should not happen at the same time.
- 16:54Okay?
- 16:55Second way is avoiding circular
- 16:58dependencies lazy annotation.
- 17:02Lazy annotation will basically delay
- 17:04injecting the dependencies, which can
- 17:06again avoid the circular dependency,
- 17:09okay?
- 17:10So, great. That is the answer to to this
- 17:13question, and all are written here in
- 17:16this book.
- 17:18What is the difference between bean
- 17:20factory and application context? All
- 17:23right. Here is the bean factory class
- 17:25code that we can use to manage the beans
- 17:29of the Spring application. I already
- 17:31explained in previous question. And here
- 17:33is the application context code, which
- 17:37is the recent and more popular way for
- 17:40again managing the beans only.
- 17:43But as I said, this is more popular and
- 17:45advanced way of managing beans.
- 17:48So first, the similarity between them is
- 17:51bean factory and application context are
- 17:55used as the containers for managing and
- 17:58accessing the beans. Okay?
- 18:01But if you focus on this diagram,
- 18:05application context will cover all the
- 18:08bean factory features and will provide
- 18:11some more features over it. Okay? So
- 18:14let's check out the differences between
- 18:16them one by one.
- 18:18So the first difference between them is
- 18:21uh bean bean factory does lazy
- 18:24initializations of beans. Okay?
- 18:27Meanings, beans are created only when
- 18:30they are requested. All right?
- 18:33Whichever bean you need, only that you
- 18:35can get. Whereas application context
- 18:37involves the early initialization of
- 18:40beans.
- 18:41Meaning, all singleton beans are created
- 18:45as soon as the application context
- 18:47context is started. All. Okay?
- 18:50Second difference is bean factory has
- 18:53limited support for other classes.
- 18:56Whereas application context has full
- 18:59support for message resources,
- 19:01transaction management, and many more
- 19:04classes. Okay? So that is one advantage
- 19:07of application context also.
- 19:10Third difference is that minimum
- 19:12integration is possible with bean
- 19:14factory.
- 19:16But application context can also
- 19:18integrate a spring's AOP and many other
- 19:22features. Integration too much is
- 19:24possible. Okay?
- 19:26Next advantage is and the differences
- 19:29bean factory supports simple resource
- 19:32loading from the class path. Okay, there
- 19:34is only I think one way.
- 19:36But application context has a very good
- 19:39mechanism for loading resource for
- 19:42loading resource resources from any kind
- 19:45of resource like you can use class path,
- 19:47file system, URL. Okay, as per your
- 19:51requirement project requirement.
- 19:53And the last difference is bean factory
- 19:56is suitable for small
- 19:58application with limited choices,
- 20:02whereas application context is preferred
- 20:04for enterprise and big applications.
- 20:08Okay?
- 20:09Great. So, these are the difference as
- 20:12as you can see the advantages of the
- 20:15applications are also here over the bean
- 20:18factory.
- 20:19All written here in this book, so that
- 20:22while revising you do not have to watch
- 20:24the whole video again. Just a look at
- 20:28this have a look at this page and that
- 20:30is enough.
- 20:34Here is a very short but very important
- 20:36question. How does a spring boot provide
- 20:39auto configuration? You already know the
- 20:41answer. This is just a reverse question.
- 20:44The answer is via spring boot starters
- 20:47like this. And the answer is written
- 20:51here also. A spring boot provide auto
- 20:52configuration by automatically
- 20:54configuring a spring application based
- 20:56on the dependency, whichever you add
- 20:59here in the class path. Okay? So, that
- 21:03will basically reduce the need of manual
- 21:06configuration. Okay, which will allow
- 21:08the developers to focus more time on
- 21:11writing the business logic rather
- 21:13focusing on the configuration related
- 21:15things, right?
- 21:17That's it.
- 21:19What is the role of a Spring Boot
- 21:21Actuator?
- 21:23See, inside your palm deck XML {dot}
- 21:26XML, you can add one Spring Boot a
- 21:28Starter Actuator like this. Okay? So,
- 21:32it's a kind of a Spring Boot a Starter
- 21:34only.
- 21:35And you can also say that it's like a
- 21:37subproject inside the a Spring Boot
- 21:40framework. And what it actually does
- 21:43after adding this, if you will go inside
- 21:46your application {dot} properties file,
- 21:48and then you can add here these points,
- 21:51health and information.
- 21:53Now, if you run the application
- 21:55with the URL Actuator
- 21:58{slash} health in the URL, you will find
- 22:01the application status which is up.
- 22:04Okay?
- 22:05Meaning, by including Actuator endpoints
- 22:09like health, information, extra etc.,
- 22:11you can get information about your
- 22:13application in the browser itself. Okay?
- 22:17In short, you can monitor your
- 22:19application.
- 22:20And here in the application {dot}
- 22:22properties, if you use asterisk, that
- 22:26means all the Actuator endpoints are
- 22:29included. So, either you can select the
- 22:31Actuator endpoints health, info, etc.
- 22:35etc., or you can all include all the
- 22:38Actuator endpoints by just using the
- 22:40asterisk. Okay?
- 22:42That's the answer to this question, and
- 22:44the simplest definition is here.
- 22:47A Spring Boot Actuator is a subproject
- 22:50of a Spring Boot that provides
- 22:52production-ready features for monitoring
- 22:56and managing the Spring Boot application
- 22:59through various endpoints. That's it.
- 23:02All right, my friend. Now, only the last
- 23:05question left. If you have watched till
- 23:08here,
- 23:09great job. It shows your dedication and
- 23:14your focus for the interviews. I wish
- 23:17you all the best for your interviews and
- 23:20your career. And yes, again, if you
- 23:23don't want to miss anything and want to
- 23:25cover more topic-wise interview
- 23:28questions on Java, then check out my
- 23:31full Java interview course, which
- 23:34contains more than 350
- 23:37plus questions from all these topics.
- 23:42Or you can use my book also for your
- 23:46interview revision. Link of the full
- 23:49course and the book is given in the
- 23:52description of this video.
- 23:55What is process and thread? What is the
- 23:58difference between them? Before
- 24:00understanding multi-threading, let's get
- 24:02a high-level idea of the process and
- 24:05thread by comparing them.
- 24:07See, inside every software application,
- 24:10there are process and threads. For
- 24:12example, like this, I will take the
- 24:15example of Windows, which is also a
- 24:18system software. Now, suppose you open
- 24:21the Chrome browser in your Windows. When
- 24:24you open the Chrome browser, one process
- 24:27will be started and running like this.
- 24:30Now, inside your operating system, you
- 24:33can see this process in the task manager
- 24:36also, right?
- 24:38Now, inside this process, there can be
- 24:40many, many tasks executing. For example,
- 24:43when you enter the URL in the browser
- 24:46and send a request, that is one task.
- 24:49And then, the response which you are
- 24:51receiving, that is another task.
- 24:54Now, these tasks can be dependent on
- 24:57each other, okay?
- 24:59Now, listen carefully. For handling,
- 25:02executing, and finishing those multiple
- 25:04tasks, we can have multiple threads like
- 25:08this.
- 25:09Okay? These threads may or may not be
- 25:13dependent on each other. They might
- 25:16share the resources with each other.
- 25:19Resources means the data, the memory,
- 25:21files, etc.
- 25:23So, for example, in a browser, if you
- 25:26send the request, then that is one
- 25:29thread, and when the response is coming,
- 25:31so response is dependent on the request.
- 25:35That's how threads can be dependent,
- 25:37okay? Meaning, threads are dependent on
- 25:41each other.
- 25:42Now, after the browser example, now
- 25:45inside the same window, if you open one
- 25:48Excel file, like this.
- 25:50That is a different process number two,
- 25:54and it has no relation with process
- 25:57number one.
- 25:58Meaning, processes are independent of
- 26:01each other, okay? They do not share the
- 26:04resources like memory, data, etc.
- 26:07between them. That is process.
- 26:10And this process two again can have one
- 26:13thread, two thread, multiple threads,
- 26:16that depends.
- 26:18Now, yes.
- 26:19This is process three for opening a text
- 26:22file, notepad, okay? And it is also
- 26:25possible that a process can have only
- 26:28one single thread inside it.
- 26:32Remember, at least one thread by default
- 26:35will always be there inside a process,
- 26:39okay?
- 26:40Because
- 26:41threads only execute task. Process is
- 26:45just like a container, okay?
- 26:47So, great. That is the very high-level
- 26:49idea of the process and thread. And in
- 26:53the next slide here, I have written the
- 26:56differences between the process and
- 26:58thread. Basically, whatever I have
- 27:00explained, that's the same thing is
- 27:02written here. So that if you revise
- 27:04later, then you do not have to listen
- 27:06the whole video again and again. That
- 27:09will be very time-taking, right?
About this transcript
This page contains the full transcript of Top 10 Java Interview Questions for 10+ years experience by Interview Happy, generated from the public captions YouTube serves with the video. The transcript has 3,549 words across 630 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.