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

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

Q.342Easy

Which of the following will cause a deadlock situation?

Q.343Medium

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

Q.344Medium

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

Q.345Medium

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

Q.346Medium

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

Q.347Medium

Which of the following best describes CyclicBarrier?

Q.348Medium

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

Q.349Easy

Which collection class is thread-safe without explicit synchronization?

Q.350Medium

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

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

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

Q.353Hard

What is the primary advantage of using ReentrantLock over synchronized?

Q.354Hard

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

Q.355Medium

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

Q.356Hard

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

Q.357Hard

What is the purpose of ForkJoinPool in Java?

Q.358Hard

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

Q.359Easy

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

Q.360Medium

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