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

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

Q.22Easy

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

Q.23Easy

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

Q.24Medium

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

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

Q.26Medium

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

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

Q.28Medium

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

Q.29Medium

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

Q.30Medium

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

Q.31Medium

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

Q.32Medium

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

Q.33Hard

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

Q.34Hard

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

Q.35Hard

What is the difference between CountDownLatch and CyclicBarrier?

Q.36Medium

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

Q.37Hard

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

Q.38Easy

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

Q.39Hard

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

Q.40Easy

Which of the following statements about Java threads is correct?