Java Threads Creation

In Java,threads can be created in multiple ways ultimately all threads creation will start by calling a method of start() API of a Thread Class.

Thread Class Initialization

Extending Thread class

public class CreationOfThread extends Thread {

	public static void main(String[] args) {
		Thread thread=new CreationOfThread();
		thread.start();
	}
	
	public void run()
	{
		System.out.println("New thread started Running using by Extending a Thread Class");
	}

}

Passing Runnable Interface

public class CreationOfThread implements Runnable {

	public static void main(String[] args) {
		CreationOfThread cot=new CreationOfThread();
		Thread thread=new Thread(cot);
		thread.start();
	}
	
	public void run()
	{
		System.out.println("New thread started Running using by Runnable Interface");
	}

}