How many ways we can create a thread in Java? Explain with pseudo code.

(Last Updated On: August 20, 2017)

There are two ways we can create a thread in multithreading in java programs that is by extending thread class and implementing Runnable interface.
Here are simple steps to create threads in java for both ways i.e. by extending Thread class and Runnbale Interface.

First way : By extending Thread Class

Steps –

  1. Create a class and extend Thread
  2. Override the run() method.
  3. Instantiate the class
  4. Call start() method

Java Code Example :

 

Second way : By Implementing Runnable Interface

Steps –

  1. Create a class and implement Runnable interface
  2. Implement the run() method.
  3. Instantiate Runnable class
  4. Instantiate the Thread class, pass Runnable class in Thread’s Constructor
  5. Call start() method

Java Code Example :