Every Thread has a Runnable -- sometimes the Runnable is the Thread itself. In any case, it's the Runnable's job to provide a run() method, and it's the Thread's job to provide the magic machinery to execute in a separate thread.
Hello, You are asking the differences between the Thread class and the Runnable interface. Both are used to make threads. Implimenting the Runnable interface is appropiate than using the Thread class. Because we can extend another class while making a thread. But if we just extend the Thread class we can't inherit from another class. There is another difference. We can create threads easily using the Thread class than using the Runnable interface. Because we can just make an object from our class.But when implementing the Runnable interface we have to do a lot making thread objects giving arguments and so on. For furthur explanations see the JLS thanks
Rajith has right, a thread is class and it implements the Runnable - a thread is a runnable and it is used by threads(direct or indirect). The diference between the two is that one is a implementation(the Thread) and the other one (Runnable) is an interface. In the oop "words" the Thread IS A Runnable(extend) because it implements the Runnable interface, can be also Thread HAS A Runnable(composition) - because on a thread you can set the threads target(via its contructor).
Difference Between Threads class & Runnable Interface is::
java has 2 ways of creating the threads... - implementing an interface - Extending a class.
Extending the class is the way java inherits methods and variable from a parent class. In this case one can only extend or inherit from a single parent class.
This limitation within java can be overcome by implementing the interfaces, which is the most common way to create threads.
Interfaces provide a way for the programmers to lay the groundwork of a class. They are used to design the requirements for a set of classes to implement. The inteface sets everything up, and the class or classes that implement the interface do all the work. The different set of classes that implement the interface have to follow the same rules.
I think i've cleared ur doubt abt the Threads class & Runnable Interface.
One difference is that you get more help in validating your code when you implement an interface. This example is a bit trivial:
It compiles fine. You might not realize that you miss-spelled run and wonder why it does not work. Probably more important when writing mouse listeners, etc. If you implemented the interface you would have got a compile time error!
In any case, the main aim of this exercise is to have the run entry point correctly available to the JRE. In this example it would have jumped into Thread's empty run method.
Ed [ December 28, 2004: Message edited by: Eddie Vanda ]
The nice thing about Standards is that there are so many to choose from!