All 45 questions
How do HashMap and ConcurrentHashMap differ in thread safety and concurrent reads and updates?
Asked in 8 of 158 interviews · last asked Oct 23 · Concept · Mid-level
Show answer
HashMap is not thread-safe; ConcurrentHashMap is. A shared HashMap needs external synchronization when any thread modifies it. ConcurrentHashMap supports concurrent reads and updates; reads generally do not block. Use HashMap for single-threaded or externally synchronized access, and ConcurrentHashMap for shared maps with concurrent updates.
- Separate calls are not automatically atomic; use putIfAbsent, compute, or merge for supported combined operations.
- HashMap allows null keys and values; ConcurrentHashMap allows neither.
- ConcurrentHashMap iterators tolerate concurrent updates but do not provide a fixed snapshot.
What the interviewer checks: The interviewer checks whether you can choose a map for shared access and avoid unsafe update sequences.
Common mistake (in 3 of 6 reviewed answers): Many answers forget that HashMap is not thread-safe, while ConcurrentHashMap is.
Other ways it was asked
- “What is the difference between Java's HashMap and ConcurrentHashMap?”
- “How is HashMap different from ConcurrentHashMap in Java?”
- “Can you explain the difference between HashMap and ConcurrentHashMap?”
What does volatile guarantee in Java, and why doesn't it make operations atomic?
Asked in 5 of 158 interviews · last asked Oct 16 · Concept · Mid-level
Show answer
In Java, `volatile` guarantees visibility and ordering: a write happens-before subsequent reads of that field. Individual reads and writes are atomic, but compound operations such as `count++` are not. An increment reads, adds, and writes in separate steps, so threads can interfere. Use synchronization or an atomic class for such updates.
- A volatile write also makes earlier writes visible to a thread that subsequently reads that volatile field.
- Volatile does not lock anything or prevent threads from running at the same time.
- Use `AtomicInteger.incrementAndGet()` or synchronization for a shared counter.
- A volatile reference does not make the referenced object's fields volatile.
What the interviewer checks: The interviewer is checking whether you distinguish visibility and ordering from atomicity.
Other ways it was asked
- “What is the role of the volatile keyword in Java?”
- “What does volatile do in Java?”
- “Can you tell me about the volatile keyword?”
When should you use volatile, synchronized, or atomic variables, and what guarantees does each provide?
Asked in 4 of 158 interviews · last asked Oct 17 · Concept · Senior
Other ways it was asked
- “In Java, what are the key differences between volatile, synchronized, and AtomicInteger regarding visibility, atomicity, and ordering guarantees?”
- “In Java, what's the difference between volatile and synchronized in terms of visibility, atomicity, and ordering?”
- “In Java, what's the difference between volatile and synchronized regarding visibility and atomicity, and when would you choose one over the other?”
What is multithreading in Java, and how does it work?
Asked in 3 of 158 interviews · last asked Sep 4 · Concept · Mid-level
Other ways it was asked
- “What is multithreading in Java, and when would you use it?”
- “What is multithreading, and when is it useful?”
What is a synchronized block in Java?
Asked in 3 of 158 interviews · last asked Sep 11 · Concept · Junior
Other ways it was asked
- “What does a synchronized block or method lock in Java?”
- “What is the difference between a synchronized method and a synchronized block in Java?”
What is the use of ConcurrentHashMap?
Asked in 3 of 158 interviews · last asked Oct 6 · Concept · Mid-level
Other ways it was asked
- “Why do we need ConcurrentHashMap?”
- “How does ConcurrentHashMap work internally?”
How do you manage concurrency and threads in Java?
Asked in 2 of 158 interviews · last asked Jun 15 · Concept · Senior
Other ways it was asked
- “Can you explain concurrency and thread management in Java?”
What is the difference between Future and CompletableFuture?
Asked in 2 of 158 interviews · last asked Oct 16 · Concept · Mid-level
What are virtual threads, how do they differ from platform threads, and what problems do they solve?
Asked in 2 of 158 interviews · last asked Apr 13 · Concept · Senior
Other ways it was asked
- “What is the difference between a Java virtual thread and a platform thread?”
- “What are virtual threads, and what problems do they help solve?”
- “Besides allowing many threads to be created, what problem do virtual threads solve?”
What is a thread in Java and Kotlin?
Asked in 2 of 158 interviews · last asked Oct 2 · Concept · Junior
Other ways it was asked
- “What is a thread in Java?”
How does Java's AtomicInteger work, and what principles does it rely on?
Asked once · last asked Apr 13 · Concept · Senior
In ConcurrentHashMap, is a lock applied to the entire map or only to part of it?
Asked once · last asked Apr 13 · Concept · Senior
If a static synchronized method is called concurrently on different objects, can multiple threads enter its critical section at the same time?
Asked once · last asked Apr 13 · Concept · Senior
What is the difference between Runnable and Thread?
Asked once · last asked Apr 17 · Concept · Junior
Where would you use a thread and Runnable in real-world Java programming?
Asked once · last asked Apr 17 · Scenario · Mid-level
How would you ensure that a Java method is executed by only one thread at a time?
Asked once · last asked May 25 · Scenario · Mid-level
Can you explain atomic types in Java?
Asked once · last asked May 25 · Concept · Mid-level
What are concurrent collections in Java, and when would you use them?
Asked once · last asked May 25 · Concept · Mid-level
What mechanisms can you use to implement multithreading in Java?
Asked once · last asked Jul 16 · Concept · Mid-level
Why is using a static WebDriver variable dangerous when running tests in parallel?
Asked once · last asked Sep 1 · Concept · Mid-level
Suppose your Selenium framework runs tests in parallel. Explain what ThreadLocal can help with and what problem it does not solve.
Asked once · last asked Sep 1 · Concept · Senior
How does synchronization in Java ensure memory visibility between threads?
Asked once · last asked Sep 1 · Concept · Mid-level
When would you choose virtual threads compared to reactive programming?
Asked once · last asked Sep 2 · Concept · Senior
What happens when you call start() on a thread? Which method is executed?
Asked once · last asked Sep 4 · Concept · Mid-level
How do you prevent double booking in Java when multiple users try to book the same item?
Asked once · last asked Sep 4 · Scenario · Mid-level
What is the use of AtomicInteger in threads?
Asked once · last asked Sep 4 · Concept · Mid-level
Is a lazily initialized Java singleton thread-safe?
Asked once · last asked Sep 11 · Concept · Mid-level
Does the volatile keyword prevent duplicate object creation in a Java singleton?
Asked once · last asked Sep 11 · Concept · Senior
What is a CompletableFuture in Java?
Asked once · last asked Sep 16 · Concept · Mid-level
When is volatile sufficient for thread safety, and when is it not? Give a concrete example of each.
Asked once · last asked Oct 13 · Concept · Senior
Can two threads access and modify the same information at the same time when it is declared volatile?
Asked once · last asked Oct 16 · Concept · Mid-level
What is Java multithreading, and how would you use it to optimize multiple external API calls?
Asked once · last asked Oct 16 · Scenario · Mid-level
Explain the Java Memory Model and the purpose of the volatile keyword.
Asked once · last asked Oct 16 · Concept · Senior
In Java, what are the key differences between Runnable and Callable? What does Future.get do in each case?
Asked once · last asked Oct 17 · Concept · Mid-level
In Java, how does ThreadLocal work, and what's a common production issue it can cause in application servers or thread pools?
Asked once · last asked Oct 17 · Concept · Senior
In Java, what happens-before guarantee does a volatile write provide, followed by a volatile read of the same variable?
Asked once · last asked Oct 22 · Concept · Senior
In Java, explain the difference between synchronized and ReentrantLock, including one capability ReentrantLock has that synchronized does not.
Asked once · last asked Oct 22 · Concept · Senior
In Java, when using an ExecutorService, what is the difference between submit and execute, and what does each return, if anything?
Asked once · last asked Oct 22 · Concept · Mid-level
What is the difference between Thread.sleep() and Object.wait() in Java?
Asked once · last asked Sep 1 · Concept · Mid-level
How do you start a thread in Java?
Asked once · last asked Sep 4 · Concept · Junior
What is ExecutorService?
Asked once · last asked Sep 4 · Concept · Junior
What does synchronized do?
Asked once · last asked Oct 2 · Concept · Mid-level
Is ConcurrentHashMap thread-safe?
Asked once · last asked Oct 6 · Concept · Junior
Is there a difference between Runnable and Callable?
Asked once · last asked Oct 16 · Concept · Junior
What are the states of a Java thread?
Asked once · last asked Oct 22 · Concept · Junior
More Java interview questions
- All Java interview questions
- Java Basics and Strings Interview Questions
- Java OOP Interview Questions
- Java Collections and Generics Interview Questions
- Java Backend, Testing and Tools Interview Questions
How this list is made
Every question here was asked by a real interviewer in a real job interview that a candidate ran MeetAssist in. After the call, the interviewer's questions are pulled from the transcript. Practice sessions, tests, exams and anything that was not a job interview are dropped.
Questions are rewritten so they make sense on their own: names of people, employers and clients are removed, and speech-to-text mistakes are fixed. Small talk, logistics and questions about one candidate's own résumé are left out. Rephrasings of the same question are merged, and the count is the number of different interviews it came up in.
The interviews come from candidates who use MeetAssist, so they lean towards software, data and AI roles: the shares describe these interviews, not every Java interview. Answers to the most asked questions are written and checked by an editor; a "common mistake" is shown only when reviews of real answers in these interviews show it, with the count.
158 interviews, 100 candidates, Sep 2025 to Oct 2026. Updated every month with new interviews.
Or add the Chrome extension