Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


What will happen to the daemon threads when the JVM exits?

  1. They continue running

  2. They are paused

  3. They are stopped

  4. They are serialized

The correct answer is: They are stopped

Daemon threads are background threads that continue to run even after the main thread ends. When the JVM exits, all threads, including daemon threads, are terminated. This is because daemon threads are meant to be supporting threads for the main thread and do not have any critical job or purpose. Therefore, they are not set to run indefinitely like normal threads. Pausing and serializing the daemon threads would prevent the JVM from exiting, as these actions would keep the threads in a running state. Thus, option A and D are incorrect. Option B is also incorrect as pausing a thread does not terminate it. Overall, when the JVM exits, all threads including daemon threads are stopped or terminated.