Advanced Java Interview Questions for Experienced Developers
1.What Is the Difference Between synchronized and ReentrantLock?
Answer: Both control thread access. ReentrantLock additionally supports timed locking, interruptible locking, and optional fairness.
2.How Does HashMap Work Internally in Java?
Answer: HashMap stores key-value pairs in buckets, using hash codes for placement and linked lists or trees to handle collisions.
3.What Is the Difference Between volatile and AtomicInteger?
Answer: Volatile ensures visibility between threads, while AtomicInteger supports atomic operations such as thread-safe increments.
4.Explain Garbage Collection in Java.
Answer: Garbage collection automatically reclaims memory occupied by objects that are no longer reachable by the application.
5.What Is the Difference Between Callable and Runnable?
Answer: Runnable does not return a result, while Callable returns a result and can throw checked exceptions.
6.What Is CompletableFuture in Java?
Answer: Runnable does not return a result, while Callable returns a result and can throw checked exceptions.
Learn more