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

What does the volatile keyword guarantee in multithreading?

Q.382Medium

In Java 21, which new feature was introduced for concurrent programming?

Q.383Medium

What is the output of this code snippet? ExecutorService es = Executors.newFixedThreadPool(2); es.execute(() -> System.out.println("Task 1")); es.shutdown();

Q.384Medium

What exception does CyclicBarrier throw when a thread is interrupted while waiting?

Q.385Hard

Consider a scenario with 3 threads updating a shared counter. Which synchronization mechanism is MOST efficient?

Q.386Hard

What is the behavior of ReentrantReadWriteLock when multiple threads perform read operations?

Q.387Hard

Which scenario can lead to livelock in multithreading?

Q.388Hard

In a ForkJoinPool, what is the primary advantage over ExecutorService for recursive tasks?

Q.389Hard

What is the output of the following code? Thread t = new Thread(() -> { throw new RuntimeException("Error"); }); t.setUncaughtExceptionHandler((thread, ex) -> System.out.println("Caught")); t.start();

Q.390Hard

Which statement about StampedLock is TRUE?

Q.391Hard

In the context of Java 21 Virtual Threads, what is a major limitation of traditional threading that Virtual Threads solve?

Q.392Easy

Which of the following methods will cause a thread to release all locks it holds while waiting?

Q.393Easy

A developer needs to ensure that exactly 5 threads complete their tasks before proceeding to the next phase. Which synchronization utility is most appropriate?

Q.394Medium

In a producer-consumer scenario using BlockingQueue, what happens when a consumer thread calls take() on an empty queue?

Q.395Medium

A multi-threaded application experiences poor performance despite having adequate CPU cores. Code inspection reveals frequent calls to synchronized blocks on shared objects. Which modern Java feature (2024-25) could optimize this without major refactoring?

Q.396Hard

Consider a ThreadLocal variable initialized in a thread pool executor with 10 threads. If the same thread is reused from the pool for a different task, what is the state of its ThreadLocal variable?

Q.397Hard

A high-frequency trading system uses AtomicInteger for concurrent counter updates. However, performance degrades as more threads access the same counter. What is the primary cause and best solution?

Q.398Easy

Which of the following is a checked exception in Java?

Q.399Medium

What is the output of the following code? int x = 10; try { x = x / 0; } catch(ArithmeticException e) { x = x + 5; } finally { x = x * 2; } System.out.println(x);

Q.400Easy

Which exception is thrown when a method receives an illegal or inappropriate argument?