iGET

Java Programming - MCQ Practice Questions

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

958 questions | 100% Free

Q.41Easy

What is the primary purpose of the volatile keyword in Java multithreading?

Q.42Easy

Which of the following will cause a deadlock situation?

Q.43Medium

In Java 21 (latest), which is a modern approach to create thread-safe operations?

Q.44Medium

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

Q.45Medium

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

Q.46Medium

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

Q.47Medium

Which of the following best describes CyclicBarrier?

Q.48Medium

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

Q.49Easy

Which collection class is thread-safe without explicit synchronization?

Q.50Medium

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

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

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

Q.53Hard

What is the primary advantage of using ReentrantLock over synchronized?

Q.54Hard

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

Q.55Medium

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

Q.56Hard

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

Q.57Hard

What is the purpose of ForkJoinPool in Java?

Q.58Hard

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

Q.59Easy

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

Q.60Medium

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