• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubts in Threading

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What is the DIFFERENCE between a THREAD and an OBJECT

Please explain with an example
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

saurabhthard aggarwal wrote:
What is the DIFFERENCE between a THREAD and an OBJECT

Please explain with an example



A thread is a thread of execution, it performs the work in a program.

An object is an instance of a class.

If you're struggling with key concepts like this, you should read a java book, not be requesting examples!!
 
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thread is like a program..
Object is instance of an class
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thread is a light weight process. A process is a specified set of instruction to be executed in some logical order.
An object is an instance of class. An object is used to call methods , access variables, an object can communicate to another object only through message passing which is dependent upon method calls. Calling objects is part of process.
As example:

Class1 // simple class
{
public void print() // method print which prints the statement "Hell Java Ranchers"
{
System.out.println("Hell Java Ranchers");
}
}

class MyThread extends Thread // thread MyThread
{
Class1 cl=new Class1(); // object of Class1
public void run()
{
cl.print(); // method of cl called whenever the thread is executed
}

}

And remember main() is also a thread from which other threads generate. I hope you have got it.
reply
    Bookmark Topic Watch Topic
  • New Topic