File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes object and instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "object and instance" Watch "object and instance" New topic
Author

object and instance

Mike Yu
Ranch Hand

Joined: Nov 17, 2001
Posts: 175
Hi,
Can someone tell me what are the differences between instance and object?


Thanks,<br />Mike
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
An instance of a class is an object.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
"Instance" is a more general concept.
As written above, an instance of a class is an object.
An instance of an association is a link (that is, between classes you have associations, between objects you have links).
An instance of a DTD or XML-Schema is an XML-file.
Does that help?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Mike Yu
Ranch Hand

Joined: Nov 17, 2001
Posts: 175
Hi, Thomas and Ilja,
Your answes are useful. I am still not very clear about the instance and object of EJB. It seems they have some diiferent meaning.
For Entity Bean, the application server creates instance, but it is assigned to an remote object only after the create method in the home interface is called.
Does someone have some ideas about the instance in this case?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Mike Yu:
For Entity Bean, the application server creates instance, but it is assigned to an remote object only after the create method in the home interface is called.

The instance they are speaking of is the object that is instanciated by the application server - the actual entity bean. The remote object is an instance of the remote interface.
Does that make things clearer for you?
Mike Yu
Ranch Hand

Joined: Nov 17, 2001
Posts: 175
That is much better! Thank you, Ilja.
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Their meanings are very close so if you are having trouble differentiating them, its ok.
An object is created from a class. Many objects may be created from the same class. Each of these objects will be referred to as "instances" of that class.
So an object is always an instance, and an instance is always an object.
ClassA refA = new ClassA();
ClassA refA2 = new ClassA();
ClassB refB = new ClassB();
ClassB refB2 = new ClassB();
refA,refA2,refB,refB2 refer to objects;
refA,refA2 refer to instances of ClassA;
refB,refB2 refer to instances of ClassB;
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: object and instance