This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes what is diff betwn Object and instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is diff betwn Object and instance" Watch "what is diff betwn Object and instance" New topic
Author

what is diff betwn Object and instance

ganesh pol
Ranch Hand

Joined: Apr 29, 2005
Posts: 151
hi friends
can any one explain what is subtle diff betwn instance and object or do they are same things?
Rajagopal Manohar
Ranch Hand

Joined: Nov 26, 2004
Posts: 183
I think they are the same,

except that there is a class called Object in java from which all other classes are derived.

many times objects and instances are used to denote the same thing i.e. A class that has been given some space in memory
ganesh pol
Ranch Hand

Joined: Apr 29, 2005
Posts: 151
RAJ
ARE U SURE ABOUT IT THAT THEY ARE SAME THING AND THEY DO NOT HAVE ANY DIFFERENCE.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
We normally think of an instance as an object formed by using the class as a template. So, different instances of the same class can have different state, but all refer to the same code.

However, in the Java runtime each class, interface, array, primitive and the keyword void will have its code also available in the form of an object which is an instance of java.lang.Class. Whenever we compile any Java file, the compiler will embed a public, static, final field named class, of the type java.lang.Class, in the emitted byte code. This field can be accessible like this:

java.lang.Class class = Myclass.class;


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
This is a very frequently asked question, so I just created http://faq.javaranch.com/view?ObjectVsInstance

You might also want to do a search on this forum.


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
Megs Maquito
Ranch Hand

Joined: May 18, 2005
Posts: 84
an object is an instance of a class.


I'm a Hood Ornament
Nischal Tanna
Ranch Hand

Joined: Aug 19, 2003
Posts: 182
Originally posted by Megs Maquito:
an object is an instance of a class.


Good reply ... just like using both the words and creating a sentence
[ June 07, 2005: Message edited by: Nischal Tanna ]

Thnx
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Just to poke Ilja with a stick now & then ... The FAQ points out that "a link is an instance of an association" which is maybe a different case than "object is an instance of a class" or maybe not. If "Association" or "RUP" are classes in a meta-model, then a link or a process are "concrete" instances. You might have to allow for instantiating objects in your brain instead of computer memory to make this work.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Stan James:
Just to poke Ilja with a stick now & then ... The FAQ points out that "a link is an instance of an association" which is maybe a different case than "object is an instance of a class" or maybe not. If "Association" or "RUP" are classes in a meta-model, then a link or a process are "concrete" instances. You might have to allow for instantiating objects in your brain instead of computer memory to make this work.


Yes, if you like to call RUP a class and the resulting process an object, that would work. I don't think I typically do that, though...
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Probably nobody but the developers of Rose think that way. But I'm sure even they have some meta-meta-meta level where it gives out. (End poking with stick)
[ June 07, 2005: Message edited by: Stan James ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is diff betwn Object and instance