21.) What does the Java Memory Model (JMM) define?
A) The physical memory layout of a Java program
B) The order in which threads execute in a Java program
C) How memory is allocated for variables in Java
D) The rules governing how threads interact with memory
22.) In the Java Memory Model, what is the purpose of the “volatile” keyword?
A) To make a variable constant and unchangeable
B) To ensure that a variable’s value is always read from and written to main memory
C) To indicate that a variable cannot be accessed by multiple threads
D) To make a variable private to a specific thread
23.) What is the purpose of a semaphore in multithreading?
A) To control access to a critical section of code by multiple threads
B) To terminate a thread when it encounters an error
C) To assign thread priorities
D) To synchronize thread execution
24.) In Java, what is the difference between a mutex and a semaphore?
A) A mutex can be acquired by multiple threads simultaneously, while a semaphore cannot.
B) A mutex can only be acquired by one thread at a time, while a semaphore can be acquired by multiple threads.
C) A mutex and a semaphore are the same thing and can be used interchangeably.
D) A mutex is used for thread prioritization, while a semaphore is used for thread synchronization.
25.) What is the purpose of a thread group in Java?
A) To organize threads based on their priority
B) To group threads for the purpose of synchronization
C) To control the execution of multiple threads as a single unit
D) To assign unique identifiers to threads
26.) What is a daemon thread in Java?
A) A thread that is part of the main program
B) A thread that is not part of any thread group
C) A thread that runs in the background and does not prevent the program from exiting
D) A thread that executes with higher priority than other threads
27.) What happens if an uncaught exception occurs in a non-daemon thread in Java?
A) The program terminates, and the exception is logged.
B) The program continues executing with the exception unhandled.
C) The program hangs indefinitely.
D) The program prints an error message and continues.
28.) Which Java class is commonly used to catch and handle exceptions thrown by threads?
A) ExceptionHandler
B) ThreadExceptionHandler
C) UncaughtExceptionHandler
D) ThreadUncaughtHandler
29.) What is a common technique for debugging multithreaded programs in Java?
A) Adding more threads to increase concurrency
B) Printing debug statements to the console
C) Reducing thread priority
D) Using synchronized blocks extensively
30.) What is a thread dump in Java?
A) A log file that records all thread-related errors
B) A snapshot of the current state of all threads in a Java program
C) A file containing compiled Java code
D) A tool for terminating threads forcibly