File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes matching reference variables with objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "matching reference variables with objects" Watch "matching reference variables with objects" New topic
Author

matching reference variables with objects

alex lesta
Greenhorn

Joined: Apr 08, 2010
Posts: 26
I'm having trouble underdstanding this code. The book wants me to match the reference variable with the object variable. can some one explain this to me.




In the book
hq[4] match id = 0
hq[3] matches id = 2
hq[1] matches 1d =1
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
alex lesta wrote:I'm having trouble underdstanding this code. The book wants me to match the reference variable with the object variable. can some one explain this to me.


What an utterly boring and pointless lesson. My first suggestion is to get another book. Surely there is one that doesn't subject you to this kind of nonsense. I can write exercises better than this.






In the book
hq[4] match id = 0
hq[3] matches id = 2
hq[1] matches 1d =1


So the last time anything was assigned to the element at 4 was when it was assigned the element at 0, which had not been replaced since the loop. So hq[4] now refers to an element with an id of 0.

The last time hq[3] was assigned, it was for the element at 2, which had not been reassigned since the loop, so hq[3] now refers to an object with an id of 2.

hq[1] was not reassigned since the loop, so it still refers to an object with an id of 1.

I hope that helps.

rc
alex lesta
Greenhorn

Joined: Apr 08, 2010
Posts: 26
Ralph Cook wrote:Thank I think i got it. I am reading head java first. can you give any referals on any other book.
alex lesta wrote:I'm having trouble underdstanding this code. The book wants me to match the reference variable with the object variable. can some one explain this to me.


What an utterly boring and pointless lesson. My first suggestion is to get another book. Surely there is one that doesn't subject you to this kind of nonsense. I can write exercises better than this.






In the book
hq[4] match id = 0
hq[3] matches id = 2
hq[1] matches 1d =1


So the last time anything was assigned to the element at 4 was when it was assigned the element at 0, which had not been replaced since the loop. So hq[4] now refers to an element with an id of 0.

The last time hq[3] was assigned, it was for the element at 2, which had not been reassigned since the loop, so hq[3] now refers to an object with an id of 2.

hq[1] was not reassigned since the loop, so it still refers to an object with an id of 1.

I hope that helps.

rc
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
If you put your response within the quote tags, it makes it look like I said it.

No, I don't have another book, just a conviction that there must be a better one somewhere.

rc
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: matching reference variables with objects