It's not a secret anymore!*
The moose likes Beginning Java and the fly likes hello... i need simple explanation for this...... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "hello... i need simple explanation for this......" Watch "hello... i need simple explanation for this......" New topic
Author

hello... i need simple explanation for this......

okey yd
Greenhorn

Joined: Oct 02, 2004
Posts: 1
Hello everyone, i just want to hear from you your simple explanation regarding the difference of instance variables and object reference variables or reference variables. what it really means to say that this is an instance variables. and what it means to say that this is object reference variable. thank you.
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
The terms instance and reference are orthogonal. Thanks for giving me an excuse to use that word.


There are three kinds of variable scopes.

There can only be one copy of a static variable with a given name for a given class. It is created when the class is first referenced in your code.

There can be one copy of an instance varable with a given name for each instance of a class. It is created when the instance is created, usually with the new operator. It exists until the class instance is garbage collected.

There can be one copy of a local variable with a given name in a given method of a class. It is created when the method is called and goes away as soon as that method returns to the caller or otherwise terminates.


There are two kinds of variable types.

A reference variable usually refers to an object. It is used to access the variables and methods of the object.

A primitive variable just contains a value, either a number or a boolean value (true or false). The type of the primitive variable, int, float, etc., determines the possible values it can have.


Mike Gershman
SCJP 1.4, SCWCD in process
Paul Santa Maria
Ranch Hand

Joined: Feb 24, 2004
Posts: 236
Did Mike's explanation answer your question?

Being an "instance variable" (i.e. being a member variable belonging to a particular object instance) and being a "reference variable" (i.e. "pointing to" some object - rather than being the object itself) are two separate things (or, as Mike put it, two things which are "orthogonal" to each other).

Looking at it another way, an "instance variable" (like "myObj.x") could, at the same time, also be a "reference variable" (as in "this.x = new someClass ()").

Did that help? Or just confuse things further for you?
[ October 03, 2004: Message edited by: Paul Santa Maria ]

Paul M. Santa Maria, SCJP
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Originally posted by Mike Gershman:
The terms instance and reference are orthogonal. Thanks for giving me an excuse to use that word.



Relating to or composed of right angles.
source: The American Heritage� Dictionary of the English Language, Fourth Edition Copyright � 2000 by Houghton Mifflin Company. Published by
Houghton Mifflin Company.

Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
In this context, orthogonal means that they are two separate things, as Paul tried to explain. Specifically, a variable can be BOTH an instance variable and a reference variable at the same time. They are not mutually exclusive terms.

HTH

Layne
[ October 05, 2004: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Originally posted by Layne Lund:
[qb]In this context, orthogonal means that they are two separate things, as Paul tried to explain. Specifically, a variable can be BOTH an instance variable and a reference variable at the same time. They are not mutually exclusive terms.

HTH

Layne

[qb]


I know what Paul was trying to explain. I just thought it funny that the title of the thread was ' ... I need a simple explanantion ....' and the word orthogonal came up. Especially as in the context that it was used is not the word's most apparent meaning.
Here is the word explained from another highly regarded source "The Compact Oxford English Dictionary"

orthogonal
/orthoggn�l/

� adjective of or involving right angles; at right angles.

In answer to the orginal question, read this section of The Java Language Specification.
[ October 06, 2004: Message edited by: Nigel Browne ]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Nigel Browne:


I know what Paul was trying to explain....
[ October 06, 2004: Message edited by: Nigel Browne ]


My apologies. I thought you were the OP. I guess I should double check before I go running my mouth, so to speak ;-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hello... i need simple explanation for this......