iGET

Java Programming - MCQ Practice Questions

Practice free Java Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.

951 questions | 100% Free

Q.61Hard

Which method in Collections can create a thread-safe Map from a non-thread-safe Map?

Q.62Hard

What is the main advantage of EnumSet over HashSet when working with Enum constants?

Q.63Hard

Consider this code: List<String> list = new CopyOnWriteArrayList<>(); list.add("A"); list.add("B"); Iterator<String> itr = list.iterator(); list.add("C"); System.out.println(itr.next());

Q.64Hard

In Java 2024, if you need a collection that automatically removes entries based on garbage collection patterns, which would you choose?

Q.65Hard

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

Q.66Hard

How does the volatile keyword help in multithreading?

Q.67Hard

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

Q.68Hard

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

Q.69Hard

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.70Hard

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

Q.71Hard

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

Q.72Hard

What is the difference between CountDownLatch and CyclicBarrier?

Q.73Hard

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

Q.74Hard

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

Q.75Hard

What is the primary advantage of using ReentrantLock over synchronized?

Q.76Hard

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

Q.77Hard

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

Q.78Hard

What is the purpose of ForkJoinPool in Java?

Q.79Hard

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

Q.80Hard

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