File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes differance between Object &  instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "differance between Object &  instance" Watch "differance between Object &  instance" New topic

differance between Object & instance

mohan gavande
Ranch Hand

Joined: Oct 07, 2004
Posts: 39
What is the differance Between Object & Instance. Actually I think
Object is Logical thing & instance is physical thing. Also when we
create instance, at that time actual memory allocation is happens.
So is any other differance in between these?
Is my thinking is true?
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
From the Java Language Specification:

An object is a class instance or an array.


A class instance is explicitly created by a class instance creation expression. An array is explicitly created by an array creation expression. ...

Mike Gershman
SCJP 1.4, SCWCD in process
Pritam Barhate

Joined: Nov 25, 2004
Posts: 15
In general Java discussions an object means same as an instance. No object is not a logical thing when creating object actual memory allocations happen.

If you are thinking about common textbook terminology, a class is logical representation and an object or an instance is where the memory allocation will happen.

Also while discusing Java, when by "object" you mean an object of class try to use all lower case letters. "Object" with first capital 'O' refers to the "class java.lang.Object" which is parent of all Java classes.

Pritam Barhate<br />A magic combination of <b>Code</b> & <b>Fire</b> : <a href="" target="_blank" rel="nofollow">codefire</a><br />----------------------------------- <br />My Open Source Projects:<br /><a href="" target="_blank" rel="nofollow">AceMDI</a>: A easy, yet powerful MDI framework that manages windows as Tabs.
mohan gavande
Ranch Hand

Joined: Oct 07, 2004
Posts: 39
Thanks for replying me.
I understand from this that in JAVA object & instance are same
Sainath Veepuri
Ranch Hand

Joined: Sep 25, 2003
Posts: 49
Hi Mohan,

"I understand from this that in JAVA object & instance are same".

I doubt if the statement you have made is right!

Vector v; --> v is the instance here. (Memory is not allocated)

Vector v = new Vector(); --> v is an object here. (Memory is allocated)

Hope you got the actual difference here.

Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342

I was taught "an object is a runtime instance of a class". For all practical purposes I have always used object and instance interchangeably, personally I don't think it's worth too much thinking time.

I'm not convinced that what Sai says above is necessarily correct...

Vector v; --> v is the instance here.

[ November 29, 2004: Message edited by: Ben Wood ]

SCJP 1.4,
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

Originally posted by sai nath:

Vector v; --> v is the instance here. (Memory is not allocated)

v is not an instance -- it is an uninitialized reference. "Instance" indicates that an object has been created. "Object"
implies the same this. "Class" indicates a template for building objects (unless you are talking about the "Class Object", which is an instance of the java.lang.Class class...). "Reference" is a variable in code -- not the object itself, but rather how we work with the objects. When an object has no refences to it, it is available for garbage collection. (There are other times as well, but this definition will suffice.)

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
It's probably worth pointing out that Object (with a capital Oh) is different from an object. Object is a class that is the ultimate grand-daddy of all classes while an object is an instance of any class. (So you are correct, "instance" and "object" are the same thing in Java -- and in most Object Oriented Programming Languages from my experience.)


Java API Documentation
The Java Tutorial
mohan gavande
Ranch Hand

Joined: Oct 07, 2004
Posts: 39
Thanks u once again now i clearly understand differance between Object
& instace
I agree. Here's the link:
subject: differance between Object & instance
It's not a secret anymore!