
Answer in brief
Java interview questions for 5 years of experience, with clear answers on concurrency, collections, JVM, performance and reliability.
Java interview questions for 5 years of experience test how you make decisions in production systems. Interviewers want to hear how you would handle real-world problems, such as a service slowing down under load or an API change that could break older clients, and why your approach fits the situation.
To help you prepare, this blog covers the questions you are most likely to face, a simple way to structure your answers, and how a free certification interview can put your profile in front of hiring managers.
Java Interview Questions on Concurrency
Java concurrency interview questions test how well you understand threads that share data and run at the same time.
When would you use a fixed thread pool? I would use a fixed thread pool to limit how many tasks run at once, for example to avoid overloading a database. I would set the pool size through load testing.
When do virtual threads help? Virtual threads help when a service runs thousands of tasks that mostly wait on a database or another service. They became a permanent feature in Java 21, but they don't add database capacity, so I would still limit how many database calls run at once.
When is volatile not enough? volatile is not enough when a thread reads, changes and writes back a value, as in count++. It shows other threads the latest value, but the three steps don't happen as one, so two threads can overwrite each other's updates. For a shared counter, I would use AtomicInteger or a lock.
How would you investigate a deadlock? I would take a thread dump, which shows threads stuck waiting for locks the others hold. To fix it, I would make every thread acquire locks in the same order.
When would you use CompletableFuture? I would use CompletableFuture to fetch data from several independent sources at the same time, with a timeout and error handling so one slow call doesn't hold up the whole request.
Limiting how much work runs at once, using atomic types or locks, acquiring locks in a consistent order and setting timeouts keep a service stable and its shared data correct when many threads run at once. Java collections questions apply the same thinking to Java's built-in data structures.
Java Interview Questions on Collections and API Design
Java collections and API design questions test whether your code keeps working when many users access it, clients retry requests and data grows. If you build APIs with Spring Boot, our guide to Spring Boot interview questions for 5 years experience covers the framework side of these questions.
Why would you choose ConcurrentHashMap? I would choose ConcurrentHashMap when several threads read and update the same map, because it handles that safely without locking the whole map. For a read-then-update step, I would use compute or merge, because calling get and then put lets another thread change the value in between.
How would you prevent a cache stampede? I would let only one request reload an expired cache entry while the others wait for its result, so the database isn't hit by every request at once. I would also add a small random delay to expiry times so popular entries don't all expire together.
How would you design an idempotent POST endpoint? I would have the client send a unique idempotency key with each request and store that key with the result. If the client retries with the same key, the server returns the stored result instead of repeating the action, such as charging a customer twice.
How would you paginate a dataset that keeps changing? I would use cursor-based pagination with a stable sort order. Offset pagination can skip or repeat items when rows are added or removed, while a cursor continues from the last item the client saw.
These approaches cover four kinds of growth: more threads on one map, more traffic to a cache, more retries and more data. Caches and large datasets also take up memory, and managing that memory is what JVM and garbage collection questions test.
JVM and Garbage Collection Interview Questions
JVM and garbage collection (GC) interview questions test whether you base memory and pause decisions on evidence, such as GC logs and latency data, rather than on a favorite collector.
Why might you keep the G1 collector? G1 has been Java's default collector since Java 9, so I would keep it if measured latency and throughput already meet our targets. Changing collectors without a proven problem adds risk without any benefit.
When would you evaluate ZGC? I would evaluate ZGC when GC pauses push response times past a tight latency target. ZGC keeps pauses very short but can use more CPU and memory, so I would compare both collectors under the same workload on the Java version we run.
Does MaxGCPauseMillis guarantee a maximum pause time? MaxGCPauseMillis does not guarantee a maximum pause time. Oracle's garbage collection tuning guide describes it as a hint the collector tries to meet but can't always, so I would treat it as a target and check actual pauses in the GC logs.
How would you investigate an out-of-memory error? I would first check the error message to see which memory area ran out, such as the heap or metaspace. Then, if the heap ran out, I would take a heap dump and look at which objects take up the most memory before deciding whether to fix a leak or increase the heap size.
Basing GC decisions on logs and memory data keeps you from changing production settings without proof. Performance tuning questions test the same habit for CPU use, threads and slow code.
Java Performance Tuning Interview Questions
Java performance tuning interview questions test how you find what is slowing a Java service down and how you check a fix before relying on it.
Where would you start with high CPU usage? I would record the service with Java Flight Recorder (JFR), a profiling tool built into the JDK, to see which methods and threads use the most CPU. The recording also shows whether that time goes to application code or to garbage collection.
How would you record a short window during an incident? I would use jcmd, a command-line tool that comes with the JDK, to start a 60-second JFR recording on the affected server. It captures CPU, memory and thread activity while the problem is happening, and before running it in production, I would confirm that I'm authorized to do so and that the recording file is stored securely.
When would you trust a microbenchmark? I would trust a microbenchmark, built with a tool such as JMH, only to test one small piece of code in isolation. JVM warm-up and other effects can make code look faster or slower than it really is, so I would confirm the result under realistic load before acting on it.
In each answer, you measure first and change code or settings only after the data points to a cause. Reliability and testing questions then ask how you release that change without breaking production.
Reliability and Testing Questions for Senior Java Developers
Reliability and testing questions for senior Java developers check how you keep a service working through releases, traffic spikes and failures, and how you catch bugs before they reach users.
How would you roll out a risky change? I would release it to a small share of traffic first, known as a canary release, and watch latency and error rates. I would agree on rollback limits before the release, so the team rolls back as soon as a limit is crossed.
How would you limit incoming work? I would set limits at the resource that runs out first, such as database connections, and decide whether extra requests wait in a queue or get rejected. I would return a clear response to rejected callers, such as HTTP 429 or 503, so they know to try again later.
How should a client retry failed calls? A client should retry only failures that are safe to repeat, cap the number of attempts, and wait a little longer before each new attempt, with a small random variation in the delay. This approach, called exponential backoff with jitter, spreads out retries from many clients so they don't overwhelm a service that is trying to recover.
How would you test concurrent code? I would combine tests that check rules the data must always follow with stress tests that run the same code many times across many threads. A concurrency bug may appear only when threads happen to run in a certain order, so it can take many runs to show up.
How would you protect an API contract? I would run contract tests before every release to check that my API's requests and responses still match what each consuming service expects. Removing or renaming a field breaks older clients, while adding an optional field usually doesn't.
These practices protect users from a bad release, a traffic spike, a retry storm, a hidden threading bug and a breaking API change.
How Should You Structure Your Answers to Java Interview Questions?
Interviewers want to hear how you reach a decision, so your answer should follow the order in which you would work through a real problem. Take the question "Our checkout API slows down during peak traffic. How would you fix it?"
Clarify the problem first, because the right fix depends on details the question leaves out. For example: "Is it slow for all users or only at peak traffic, and what response time do we need?"
Compare two options, because naming what each one costs shows you understand trade-offs. For example: "Caching product data cuts database load but can show outdated prices. Read replicas keep data fresher but cost more."
Name the main risk of your choice, because any fix can fail in production. For example: "If the cache server goes down, every request falls back to the database at once."
Say how you would measure success, because without a number, nobody can check whether the fix worked. For example: "I'd track p99 latency, the response time 99% of requests stay under, and keep it below 300 milliseconds at peak."
Use these steps when you practice. Since it's hard to judge your own answers, a mock interview or a certification interview gives you feedback from someone else.
How Can Berri Talent Certification Help Java Developers With 5 Years of Experience?
Berri Talent certification lets Java developers prove their skills once and skip the first-round (L1) interview at Berribot's partner companies. The Berri Certified interview is free, takes 45 to 60 minutes, and is run by Berri MasterMind, Berribot's AI interviewer.
Berri MasterMind evaluates your technical, behavioral and communication skills in one interview. It adapts its questions to your answers in real time to test how well you understand each topic. Interviews for technical roles, such as Java developer, can include live coding in a built-in code editor, and using AI tools to answer is not allowed.
If you clear the bar, your performance decides whether you earn a Gold or Silver tier. If you agree at registration, your certified profile is shared with hiring managers at partner companies with matching roles. Certification does not guarantee an interview or a job offer.
If you don't clear the bar, you get a feedback report on where to improve, free preparation through Berri Tutor and the option to retake the interview after 30 days.

Get certified and put your profile in front of hiring managers.

Every score, with the transcript that produced it
Explainable rubric scoring and human review โ so both sides can trust the result.
See how scoring works

