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.81Hard

Consider a scenario: Thread A is waiting in wait() inside a synchronized block. Thread B calls notify(). What is the state of Thread A?

Q.82Hard

In a high-concurrency scenario using Java 21, which approach is recommended for I/O-bound operations?

Q.83Hard

What is the purpose of the strictfp modifier in the context of multithreading?

Q.84Hard

In a producer-consumer problem, what is the ideal synchronization mechanism?

Q.85Hard

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

Q.86Hard

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

Q.87Hard

Which scenario can lead to livelock in multithreading?

Q.88Hard

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

Q.89Hard

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.90Hard

Which statement about StampedLock is TRUE?

Q.91Hard

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

Q.92Hard

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.93Hard

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.94Hard

Analyze the code: try { return 5; } finally { return 10; } What will be returned?

Q.95Hard

What happens if an exception is thrown in the finally block?

Q.96Hard

Analyze the nested try-catch: try { try { int x = ; } catch(NullPointerException e) { System.out.println("Inner"); } } catch(ArithmeticException e) { System.out.println("Outer"); }

Q.97Hard

What will be printed? public class ExceptionTest { public static void main(String[] args) { try { testMethod(); } catch (Exception e) { System.out.println("Caught"); } } public static void testMethod() { try { throw new RuntimeException("Error"); } finally { System.out.println("Finally"); } } }

Q.98Hard

Which of the following is NOT a characteristic of Exception class in Java?

Q.99Hard

Which of the following cannot throw a checked exception without being declared in throws clause?

Q.100Hard

What is the execution order in try-catch-finally for nested exception handling?