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
In Java multithreading, which method is used to pause the execution of a thread for a specified number of milliseconds without releasing locks?
What is the primary purpose of the synchronized keyword in Java?
Which of the following statements about the notify() method is correct?
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(); } }
Which exception is thrown when a thread is interrupted while waiting?
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?
What is the return type of the join() method in Java threading?
Which of the following is a thread-safe collection in Java that can be used without explicit synchronization?
What happens if you call interrupt() on a thread that is not in a waiting or sleeping state?
Which method is used to check the current state of a thread in Java?
In the context of synchronized methods, what is acquired and released automatically?
What is the main advantage of using ExecutorService over directly creating threads?
Consider the following code. What will be the likely behavior? java synchronized void method1() { method2(); } synchronized void method2() { }
Which class is used to synchronize the execution of multiple threads at a specific point?
What is the difference between CountDownLatch and CyclicBarrier?
In a multithreaded application, what does the term 'context switching' refer to?
What will happen if a thread tries to acquire a lock it already holds while inside a synchronized method?
Which of the following best describes the purpose of the Runnable interface in Java?
In a high-concurrency scenario with 2024-25 exam patterns, which Java construct provides the best lock-free approach for thread safety?
Which of the following statements about Java threads is correct?