This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Getting it right from the beginning : Object vs Reference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting it right from the beginning : Object vs Reference" Watch "Getting it right from the beginning : Object vs Reference" New topic
Author

Getting it right from the beginning : Object vs Reference

leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
Would someone be willing to tell me if I have forgotten anything in this example code? I'm trying to comment on everything so that I get this right from the get-go.

I really appreciate everyone's help.
Leo
[ edited to reduce the left-right scrolling -ds ]
[ January 31, 2004: Message edited by: Dirk Schreckmann ]

Thanks, leo
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Writing similar example programs is exactly what I started doing when I first began learning Java. It's a practice I still hold today, as I learn some knew API or technology.
It looks like you're understanding things.
//Object variables contain a null pointer upon declaration,
//meaning that they don't point to any created object.

Not exactly. Instance member variables, static class member variables, and array members are always automatically initialized upon declaration. Had your example apple variable been simply declared in a method, it would not have been initialized automatically to null as it is when it's an instance member.
If you haven't already stumbled across it, I'd recommend a read of a couple JavaRanch Campfire Stories - "Cup Size" and "Pass-by-Value Please" - just to help clarify the situation.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
GeeCON Prague 2014
 
subject: Getting it right from the beginning : Object vs Reference