iGET

Java Programming - MCQ Practice Questions

Java interviews and campus tests lean heavily on object oriented behaviour rather than API recall. This set covers inheritance and polymorphism, interfaces and abstract classes, the collections framework, exception handling, multithreading, string handling, and JVM basics such as garbage collection. Output based questions are included because they expose the gaps that theory questions hide.

951 questions | 100% Free

Q.1Hard

What happens when wait() is called from a thread that doesn't hold the lock?

Q.2Hard

How does the volatile keyword help in multithreading?

Q.3Hard

What will happen if you call sleep() inside a synchronized block?

Q.4Hard

Which interface allows multiple threads to access a resource with a permit system?

Q.5Hard

Consider code where Thread A holds Lock1 and waits for Lock2, while Thread B holds Lock2 and waits for Lock1. What is this scenario called?

Q.6Hard

Consider the following code. What will be the likely behavior?
java
synchronized void method1() { method2(); }
synchronized void method2() { }

Q.7Hard

Which class is used to synchronize the execution of multiple threads at a specific point?

Q.8Hard

What is the difference between CountDownLatch and CyclicBarrier?

Q.9Hard

What will happen if a thread tries to acquire a lock it already holds while inside a synchronized method?

Q.10Hard

In a high-concurrency scenario with 2024-25 exam patterns, which Java construct provides the best lock-free approach for thread safety?

Q.11Hard

What is the primary advantage of using ReentrantLock over synchronized?

Q.12Hard

In a high-traffic web application using Java 21 Virtual Threads, what is the main performance benefit?

Q.13Hard

Which pattern should be used to safely publish data from one thread to another?

Q.14Hard

What is the purpose of ForkJoinPool in Java?

Q.15Hard

If a thread is blocked waiting for I/O, what happens when interrupt() is called on it?

Q.16Hard

Consider a scenario: Thread A is waiting in wait() inside a synchronized block. Thread B calls notify(). What is the state of Thread A?

Q.17Hard

In a high-concurrency scenario using Java 21, which approach is recommended for I/O-bound operations?

Q.18Hard

What is the purpose of the strictfp modifier in the context of multithreading?

Q.19Hard

In a producer-consumer problem, what is the ideal synchronization mechanism?

Q.20Hard

Consider a scenario with 3 threads updating a shared counter. Which synchronization mechanism is MOST efficient?