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

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

Q.82Hard

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

Q.83Hard

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

Q.84Hard

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

Q.85Hard

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

Q.86Hard

Which scenario can lead to livelock in multithreading?

Q.87Hard

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

Q.88Hard

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

Which statement about StampedLock is TRUE?

Q.90Hard

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

Q.91Hard

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

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

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

Q.94Hard

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

Q.95Hard

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

Q.96Hard

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

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

Q.98Hard

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

Q.99Hard

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

Q.100Hard

What is suppressed exception in Java (introduced in Java 7)?