iGET

Java Programming - MCQ Practice Questions

Java interviews and campus tests lean heavily on object oriented behaviour rather than API recall. This set covers inheritance and polymorphism, interfaces and abstract classes, the collections framework, exception handling, multithreading, string handling, and JVM basics such as garbage collection. Output based questions are included because they expose the gaps that theory questions hide.

951 questions | 100% Free

Q.21Hard

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

Q.22Hard

Which scenario can lead to livelock in multithreading?

Q.23Hard

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

Q.24Hard

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

Which statement about StampedLock is TRUE?

Q.26Hard

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

Q.27Hard

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

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?