Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

476 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 321–330 of 476
Topics in Java Programming
Q.321 Medium Multithreading
What is thread pooling and which class is commonly used for it?
A Creating individual threads, Thread class
B Reusing a fixed set of threads, ExecutorService
C Synchronizing threads, Synchronized class
D Managing thread priority, ThreadGroup
Correct Answer:  B. Reusing a fixed set of threads, ExecutorService
EXPLANATION

Thread pooling reuses a fixed set of threads instead of creating new ones for each task. ExecutorService provides convenient methods for thread pool management.

Take Test
Q.322 Medium Multithreading
What is a deadlock in multithreading?
A When a thread terminates unexpectedly
B When two or more threads are blocked indefinitely, waiting for each other
C When a thread has the lowest priority
D When a thread accesses a null pointer
Correct Answer:  B. When two or more threads are blocked indefinitely, waiting for each other
EXPLANATION

A deadlock occurs when two or more threads are blocked forever, waiting for each other to release resources they need.

Take Test
Q.323 Medium Multithreading
What is a daemon thread in Java?
A A thread that runs in the background and doesn't prevent JVM shutdown
B A thread that has the highest priority
C A thread that cannot be interrupted
D A thread that runs system services
Correct Answer:  A. A thread that runs in the background and doesn't prevent JVM shutdown
EXPLANATION

A daemon thread runs in the background and doesn't prevent the JVM from exiting. When all non-daemon threads finish, the JVM exits even if daemon threads are running.

Take Test
Q.324 Medium Multithreading
Which class provides thread-safe operations on shared variables in Java?
A Thread
B Runnable
C AtomicInteger
D Synchronizer
Correct Answer:  C. AtomicInteger
EXPLANATION

The AtomicInteger class (and other Atomic classes) provides thread-safe operations without explicit synchronization using low-level atomic operations.

Take Test
Q.325 Medium Multithreading
What is the difference between notify() and notifyAll()?
A notify() wakes one waiting thread, notifyAll() wakes all waiting threads
B notifyAll() wakes one thread, notify() wakes all threads
C They are identical in functionality
D notify() is for static methods, notifyAll() is for instance methods
Correct Answer:  A. notify() wakes one waiting thread, notifyAll() wakes all waiting threads
EXPLANATION

notify() wakes up a single thread that is waiting on the object's monitor, while notifyAll() wakes up all threads waiting on that object.

Take Test
Q.326 Medium Multithreading
Consider a synchronized method. Can multiple threads call it simultaneously on the same object?
A Yes, multiple threads can call it anytime
B No, only one thread can execute it at a time for the same object
C Yes, if they are different thread types
D Only if the method is static
Correct Answer:  B. No, only one thread can execute it at a time for the same object
EXPLANATION

A synchronized method locks the object, allowing only one thread to execute it at a time for that object instance.

Take Test
Q.327 Medium Multithreading
What is a race condition in multithreading?
A When threads compete for CPU resources
B When the outcome of a program depends on the timing of thread execution
C When a thread runs faster than others
D When threads communicate with each other
Correct Answer:  B. When the outcome of a program depends on the timing of thread execution
EXPLANATION

A race condition occurs when multiple threads access shared data and the final result depends on the order of execution, which is unpredictable.

Take Test
Q.328 Medium Multithreading
What will be the output of calling start() multiple times on the same thread object?
A Thread will run multiple times
B IllegalThreadStateException will be thrown
C Thread will run once and ignore subsequent calls
D It depends on the JVM implementation
Correct Answer:  B. IllegalThreadStateException will be thrown
EXPLANATION

Calling start() on an already started thread throws IllegalThreadStateException because a thread can only be started once.

Take Test
Q.329 Medium Multithreading
Which of the following is NOT a thread state in Java?
A NEW
B RUNNABLE
C WAITING
D SLEEPING
Correct Answer:  D. SLEEPING
EXPLANATION

The thread states are NEW, RUNNABLE, RUNNING, BLOCKED, WAITING, TIMED_WAITING, and TERMINATED. SLEEPING is not an official state.

Take Test
Q.330 Medium Multithreading
What is the purpose of the synchronized keyword in Java multithreading?
A To increase thread speed
B To prevent thread interference and memory consistency errors
C To create new threads automatically
D To pause all threads
Correct Answer:  B. To prevent thread interference and memory consistency errors
EXPLANATION

The synchronized keyword provides mutual exclusion to ensure that only one thread can access a resource at a time, preventing race conditions.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips