20 Advanced Core Java Interview Questions for Experienced Developers of 5 to 10 Years
These are difficult and advanced core Java questions for 5 to 10 years Experienced Java developers
Hello friends, if you are preparing for your next Java Developer interview and looking for a Senior Developer or Team Lead position, then you will have to prepare hard.
Earlier, I shared 50 Microservices Questions, 35 Java Questions, 30 Spring Framework Questions, and 7 System Design Problems, and in this article, I am going to share some advanced core Java interview questions for experienced programmers i.e., someone who has more than 5 years of experience in Java programming, mostly in core Java, but JEE work is also fine.
I have found that once you become senior and your experience grows, you no longer see questions like String vs StringBuilder or Vector vs ArrayList; instead, many companies ask about class loaders, Garbage collectors, concurrency, and about JVM.
I have started collecting some core Java questions for my preparation and today I am going to share some with you. I don’t have their answer, So, I am looking forward to you guys answering them, of course, only if you know.
By the way, if you are new to the Java programming language or want to improve your Java skills, then you can also take the following best Java courses to get better:
Java Programming and Software Engineering Fundamentals Specialization Certificate on Coursera
CodeGym (learn Java by building Games)
These are my favorite online courses and platforms to learn Java from scratch and also build your Java skills.
20 Advanced Core Java Interview Questions for Senior Developers
Here are the 20 questions that I think every experienced Java developer should practice. They touch advanced topics like class loaders, garbage collection, performance, JVM internals, as well as design patterns , which are really crucial for Java developers.
1. What are classloaders and the different types of classloaders in Java?
In Java, classloaders are responsible for dynamically loading classes into the JVM at runtime. Instead of loading all classes upfront, the JVM uses classloaders to bring in classes only when they are needed. This makes Java flexible and modular.
There are three main types of classloaders:
Bootstrap ClassLoader: Loads the core Java classes (like those from
java.lang
,java.util
, etc.) from the JDK.Extension (Platform) ClassLoader: Loads classes from the
ext
directory or platform extensions.Application (System) ClassLoader: Loads classes from the application’s classpath, such as the
src
orlib
folders.
2. You are using a third-party library in your project, which you think may be replaced in the future. How will you code so it’s easier to change the library later?
Whenever I use a third-party library that might change, I always abstract it behind an interface or wrapper.
For example, instead of calling library methods directly throughout the codebase, I create a service layer (like PaymentService
or CacheManager
) that uses the library internally.
This way, if I ever decide to switch to a new library, I just need to update the implementation inside that wrapper, not across the entire project.
3. You have two similar-looking methods where most logic is the same except the dataset and a custom conversion step. How will you refactor this code?
In this case, I would apply the Template Method or Strategy Design Pattern. I’d extract the common logic into a base method and allow the variable part — the dataset and conversion — to be passed as a function or strategy.
For example, I can define a method that takes a Function<Data, Object>
as a parameter for the custom conversion logic. This keeps the core logic clean, avoids duplication, and makes the code more flexible.
4. When does using Microservice architecture make sense and when is a Monolith more appropriate?
Microservices make sense when the application is large, modular, and developed by multiple teams that need independent deployment and scaling. They shine when services evolve at different rates or have different scaling needs.
However, a Monolith is often better for small to medium-sized projects where latency between services would add unnecessary complexity. Monoliths are easier to develop, test, and deploy when the system is relatively simple and tightly coupled.
5. What problem is solved by the SAGA design pattern in Microservices? What are the alternatives?
The SAGA pattern helps manage distributed transactions across microservices, ensuring data consistency without using a traditional distributed transaction manager. It breaks a large transaction into smaller local transactions, coordinated through events or commands.
There are two types of Saga implementations: Choreography (event-driven) and Orchestration (centralized coordinator).
Alternatives include using Two-Phase Commit (2PC) or Event Sourcing, though these have higher complexity and coordination overhead.
6. What is the Bootstrap ClassLoader, and how does it work?
The Bootstrap ClassLoader is the root classloader in the JVM. It’s written in native code (usually C/C++) and loads the core Java classes from the rt.jar
or modules in the JDK, such as java.lang
and java.util
. It doesn’t have a parent and is part of the JVM itself.
7. What is the Extension ClassLoader and how does it work?
The Extension ClassLoader (or Platform ClassLoader in modern Java versions) loads classes from the JDK’s lib/ext
directory or system extensions. It’s a child of the Bootstrap loader and provides functionality that extends the core Java libraries.
8. What is the Application ClassLoader and how does it work?
The Application (System) ClassLoader is responsible for loading classes from the application’s classpath — usually from JAR files or compiled classes under src
or target
. It’s the default loader for most application-level code and is the child of the Extension ClassLoader.
9. When does an object become eligible for garbage collection?
An object becomes eligible for garbage collection when there are no more live references to it — meaning no part of the program can reach it anymore.
10. Who performs garbage collection?
The JVM’s Garbage Collector (GC) automatically performs garbage collection. It runs in the background, managed by the JVM, to reclaim memory from unreachable objects.
11. When does the garbage collector run?
The GC runs automatically when the JVM determines that memory is low or during idle CPU time. Developers can suggest it by calling System.gc()
, but it’s ultimately up to the JVM when it actually runs.
12. Which algorithm does the garbage collector use?
The JVM uses different algorithms based on the GC type, but the most common one is Mark and Sweep. It marks reachable objects and then sweeps unreferenced ones to free memory.
13. List out different garbage collection algorithms.
Some well-known GC algorithms include:
Mark and Sweep
Mark and Compact
Copying Collector
Generational Garbage Collection
G1 (Garbage First) Collector
ZGC (Z Garbage Collector)
Shenandoah GC
14. Can we force the JVM to perform garbage collection?
No, we can’t force it. We can only request it using System.gc()
or Runtime.getRuntime().gc()
, but it’s up to the JVM to decide when to actually run GC.
15. How to request the JVM to perform a garbage collection operation?
I can request GC by calling:
System.gc();
or
Runtime.getRuntime().gc();
However, this is just a request, not a command.
16. Explain the purpose of the finalize()
method in relation to Garbage Collection.
The finalize()
method was originally used to release resources before an object was garbage collected. However, it’s now deprecated because it’s unpredictable — the JVM may never call it. We should use try-with-resources
or close()
instead.
17. How many times is the finalize()
method called on an object?
The finalize()
method is called at most once by the JVM before the object is garbage collected.
18. Once an object is garbage collected, can it become reachable again?
No. Once the GC reclaims an object’s memory, it’s permanently gone. However, before that happens, if the object somehow reassigns itself to a reachable reference in finalize()
, it can “resurrect” temporarily — though this is a bad practice.
19. How to write code that makes an object eligible for garbage collection?
Here’s a simple example:
MyObject obj = new MyObject();
obj = null; // Now eligible for GC
Or, if an object goes out of scope (like inside a method), it also becomes eligible.
20. What is the difference between the State and Strategy Design Pattern?
Both patterns encapsulate behavior, but their intent differs:
State Pattern: Behavior changes based on the object’s internal state. The object transitions between states, each with its own behavior.
Strategy Pattern: Behavior changes externally by swapping different algorithms or strategies at runtime, without changing the object’s state.
You can also answer them in your own way, but always include this format to present your thought process confidently during a senior-level technical interview.
Java and Spring Interview Preparation Material
Before any Java and Spring Developer interview, I always read the following resources
Grokking the Java Interview: click here
I have personally bought these books to speed up my preparation.
You can get your sample copy here, check the content of it, and go for it
Grokking the Java Interview [Free Sample Copy]: click here
If you want to prepare for the Spring Boot interview you follow this consolidated ebook, it also contains microservice questions from spring boot interviews.
Grokking the Spring Boot Interview
You can get your copy here — Grokking the Spring Boot Interview
That’s all, friends, these are a few Core Java Interview questions you can prepare for senior-level Java interviews. As I said, these questions are mostly asked to experienced Java programmers, so preparing them in advance is better.
Good luck with your Java Interview.
By the way, if you are new to the Java programming language or want to improve your Java skills, then you can also check out the following best Java courses to get better:
Java Programming and Software Engineering Fundamentals Specialization Certificate on Coursera
CodeGym (learn Java by building Games)
These are my favorite online courses and platforms to learn Java from scratch and also build your Java skills.
All the best for your Java Interviews !!