• 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
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

object Vs instance

 
Ranch Hand
Posts: 98
  • 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 an instance and a Object ?
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
     
    To get a wish, you need a genie. To get a genie, you need a lamp. To get a lamp, you need a tiny ad:
    Thread Boost feature
    https://coderanch.com/t/674455/Thread-Boost-feature
    reply
      Bookmark Topic Watch Topic
    • New Topic