Java Multithreading Question and Answers

1. What is a thread?
  A thread is a set of instructions executing apart from other threads (with its own stack) but sharing the same memory space (with the same heap).
 
Your Name Your Email-ID
Your Answer
2. How can we create a thread in java?
  There are two ways to create a thread in java – first by implementing runable interface and then creating a thread object from it and second is to extend the thread class.
 
Your Name Your Email-ID
Your Answer
3. What is the difference between user thread and daemon thread?
 
  • When we create a thread in java program, it's known as user thread.
  • A daemon thread runs in background and doesn't prevent JVM from terminating.
  • When there are no user threads running.
  • JVM shutdown the program and quits.
  • A child thread created from daemon thread is also a daemon thread.
 
Your Name Your Email-ID
Your Answer
4. When is a thread created?
 
  • A thread is created by the VM behind the scenes during a call to the start() method.
  • It begins its life inside the run() method of the thread subclass instance whose start() method as called.
 
Your Name Your Email-ID
Your Answer
12345678910 Page 1 of 10