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

In Java multithreading, which method is used to pause the execution of a thread for a specified number of milliseconds without releasing locks?

Q.322Easy

What is the primary purpose of the synchronized keyword in Java?

Q.323Easy

Which of the following statements about the notify() method is correct?

Q.324Medium

What will be the output of the following code snippet? java class Test extends Thread { public void run() { System.out.print("T"); } } public class Main { public static void main(String[] args) { Test t = new Test(); t.run(); t.start(); } }

Q.325Easy

Which exception is thrown when a thread is interrupted while waiting?

Q.326Medium

Consider a scenario where Thread A acquires Lock1 and tries to acquire Lock2, while Thread B acquires Lock2 and tries to acquire Lock1. What situation arises?

Q.327Easy

What is the return type of the join() method in Java threading?

Q.328Medium

Which of the following is a thread-safe collection in Java that can be used without explicit synchronization?

Q.329Medium

What happens if you call interrupt() on a thread that is not in a waiting or sleeping state?

Q.330Medium

Which method is used to check the current state of a thread in Java?

Q.331Medium

In the context of synchronized methods, what is acquired and released automatically?

Q.332Medium

What is the main advantage of using ExecutorService over directly creating threads?

Q.333Hard

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

Q.334Hard

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

Q.335Hard

What is the difference between CountDownLatch and CyclicBarrier?

Q.336Medium

In a multithreaded application, what does the term 'context switching' refer to?

Q.337Hard

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

Q.338Easy

Which of the following best describes the purpose of the Runnable interface in Java?

Q.339Hard

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

Q.340Easy

Which of the following statements about Java threads is correct?