Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

differance between Object & instance

 
mohan gavande
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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. ...
 
Pritam Barhate
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
mohan gavande
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying me.
I understand from this that in JAVA object & instance are same
 
Sainath Veepuri
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks,
SAi.
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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 ]
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)

Layne
 
mohan gavande
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks u once again now i clearly understand differance between Object
& instace
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic