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
Consider the code:
synchronized void method1() { wait(); }
If wait() is called without a lock, what happens?
What is the purpose of the yield() method in Java threading?
Which Java class provides thread-safe operations using Compare-And-Swap (CAS)?
What does the volatile keyword guarantee in multithreading?
In Java 21, which new feature was introduced for concurrent programming?
What is the output of this code snippet?
ExecutorService es = Executors.newFixedThreadPool(2);
es.execute(() -> System.out.println("Task 1"));
es.shutdown();
What exception does CyclicBarrier throw when a thread is interrupted while waiting?
In a producer-consumer scenario using BlockingQueue, what happens when a consumer thread calls take() on an empty queue?
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?