aspose file tools*
The moose likes Java in General and the fly likes object Vs 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 Vs instance" Watch "object Vs instance" New topic
Author

object Vs instance

eswar kumar
Ranch Hand

Joined: Oct 20, 2002
Posts: 98
What is the difference between an instance and a Object ?
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Well, that capitol O in Object means (hopefully) that you are referring to the class of objects defined by the class java.lang.Object.
If you are asking what the difference between an "object" and an "instance", then simply an object is any tangible item in the JVM's memory. "objects" will be instantiations of classes. Instances of course means the same thing.
There are probably some semantic differences from what I've said here, based on OO terminology -- which I'm sure somebody will toss in.
But all in all, all objects are instances of classes, even class objects (ex String.getClass()) -- "Object" proper -> java.lang.Object is a class of objects, which may be instantiated at various times during your program to achieve some wonderful thing.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I'd call little-o object and instance the same thing ... an object is an instance of a class. Some times it is important to be very precise about class and object ... class being a definition of a thing and object being an example thing of that class.
For example, when you write a method call in your code the compiler checks that the class of an argument you pass matches the class of the parameter on the method. But at run time, you're passing a real object and the JVM checks that the object you are passing is an instance of a class that matches the method.
By the way: Capital-O Object is really confusing because it is (get this!) a class. Yikes! That's purely a Java thing - blame Sun for confusing us all.
Reading back on this, I think Nathanial and I said exactly the same thing with slightly different emphasis. I hope reading it twice helps!
[ December 13, 2003: Message edited by: Stan James ]

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
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
A point that one might consider a subtle difference between the term object and instance (though I agree with Stan and Nathaniel that for all intents and purposes they mean the same thing) is that an instance is a single instantiation of a class with a unique identity. That may not seem important except for the fact that it is one of the tenets of OO theory and we use that fact in all sorts of ways in our programming, for example we can use any instance as key in a Map and be assured that the value stored under that key can be retrived later (assuming that the hashcode and equals methods for the class have not been overridden in such a manner that two different instances might appear to be the same object).


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
With three very good responses already, I hesitate to add another, but I love chewing on this stuff so ...
I also see subtle differences between object, class and instance.
  • An object is the logical concept of a type of thing: a car
  • A class defines the data and behavior of an object: Car { licensePlate, model, color }
  • An instance is a single, unique memory allocation of a class: Car @ 0x032AD892 [ "2EJB141", "Porsche 911", Color.RED ]

  • [ December 14, 2003: Message edited by: David Harkness ]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: object Vs instance