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.341Medium

What will be the output of the following code? Object lock = new Object(); synchronized(lock) { synchronized(lock) { System.out.println("Nested"); } }

Q.342Medium

Which interface would you use to submit multiple tasks and wait for all of them to complete?

Q.343Medium

What is the difference between notify() and notifyAll() in Java?

Q.344Medium

Which of the following best describes CyclicBarrier?

Q.345Medium

What happens when a thread acquires a lock on an object and then calls wait()?

Q.346Easy

Which collection class is thread-safe without explicit synchronization?

Q.347Medium

In a scenario where Thread A holds Lock1 and waits for Lock2, while Thread B holds Lock2 and waits for Lock1, what is this called?

Q.348Medium

What is the output of this code? ExecutorService executor = Executors.newSingleThreadExecutor(); executor.submit(() -> System.out.println("Task 1")); executor.submit(() -> System.out.println("Task 2")); executor.shutdown();

Q.349Medium

Which method is used to forcefully stop a thread in modern Java?

Q.350Hard

What is the primary advantage of using ReentrantLock over synchronized?

Q.351Hard

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

Q.352Medium

What happens if an exception is thrown inside a synchronized block?

Q.353Hard

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

Q.354Hard

What is the purpose of ForkJoinPool in Java?

Q.355Hard

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

Q.356Easy

Which method is used to prevent race conditions by allowing only one thread to access a resource at a time?

Q.357Medium

In Java 21 Virtual Threads, what is the key advantage over platform threads?

Q.358Medium

What does the volatile keyword guarantee in Java multithreading?

Q.359Medium

What is the output of the following code? volatile int counter = 0; counter++; // in multiple threads Which issue may occur?

Q.360Medium

What is CyclicBarrier used for in multithreading?