iGET

Java Programming - MCQ Practice Questions

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

951 questions | 100% Free

Q.41Medium

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

Q.42Medium

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

Q.43Medium

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

Q.44Medium

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

Q.45Medium

Which of the following best describes CyclicBarrier?

Q.46Medium

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

Q.47Easy

Which collection class is thread-safe without explicit synchronization?

Q.48Medium

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

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

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

Q.51Hard

What is the primary advantage of using ReentrantLock over synchronized?

Q.52Hard

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

Q.53Medium

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

Q.54Hard

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

Q.55Hard

What is the purpose of ForkJoinPool in Java?

Q.56Hard

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

Q.57Easy

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

Q.58Medium

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

Q.59Medium

What does the volatile keyword guarantee in Java multithreading?

Q.60Medium

What is the output of the following code? volatile int counter = 0; counter++; // in multiple threads Which issue may occur?