05.0 Java Notes‎ > ‎

Java: Variables, References and Objects

Adapted with permission from Arnold Rosenbloom, University of Toronto 
*added by MisterV
Variable is a named loaction in main memory.

Primitive Variable
  • A primitve variable will hold the value of a primitive data type
    ie. :byte, short, int, long, float, double, char, boolean.
Referenced Variable
  • A Reference holds the address of an instance of an class (a.k.a. an object)
  • A reference is NOT the instance 
  • The VALUE of a reference is the address it holds
  • Speed Dial analogy (no Inheritence)
Using Objects
Booloon b1=new Booloon(); does the following :
  1. Create a new instance of Balloon
  2. Call the initialization code for a new Balloon (constructor)
  3. Create a new reference to Balloon called b1
  4. Assign the address of the newly created/initialized balloon to b1
The following are equivalant statments:
Booloon b1=new Booloon();Booloon b1;
b1=new Booloon();

Comments