Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

== (equal to operator) and object references 4

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I'm a newbie, trying to learn OO via a Java course.

I'm on a section regarding expressions, operators / operands.

It states that if you use the == (equals to) operator with any of the opreands being a reference variable to instances of objects, it will always return false if they both do not contain the reference to the same object instance.

Is this just in java or true of any OO language when using object vars and the == (equals to) operator.

Also I was wondering if it is possible to create a primitave variable type which is equal to the value of the reference of the object instance (it's memory address).

Not sure I've explained that well, but it's like in perl, you can make a standard string scalar variable my $myvar = the memory reference of say a hash or array.

So it is a scalar variable not an object reference type variable.

Is this logic going to cause me problems and should I forget anything I know of other languages?

It's just it seems odd you need to create a variable of a class type if all it is going to do is hold a memory reference, not the actual object, which is all an object referecne is.

how big is an object reference variable if it isn't actually holding the object and its state attributes?

It just seems a bit alien to me to create two vars which are seamingly different (one being an object reference) and the other being a refrence to the object variable which is referencing the object instance...

my example..

Code:
Book myBook = new Book();
Book myBook2 = myBook;

why does myBook2 have to be a class defined reference variable, when it's just holding a memory location to the object referenced by myBook.

Any help undertanding why is appreciated.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
this isn't entirely true. each language also requires an compiler. the compiler translates said language to merge module. the MM consists of Intermediate Language assember (IL) and metadata.
I'll take your word for it, All i know is I read some blurb when .NET came out about how you could develop in any language even COBOL via .NET, so a programmer can use their native language and then .NET allows it to be complied as required.

Anyways, don't wont to cloud my head with anything other than Java for the moment, it's hard work enough, without throwing other stuff into the mix ;-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top