The java language does a good job of hiding the complexity of memory and object management.
Objects are manipulated by references, which act like pointers in other languages.
Object myObject = new Object();
myObject is a reference variable that now contains a reference to a new object of type Object.
Example of manipulating references:
String myStringObject = new String("I am a string");
System.out.println(myStringObject.length());//this is a method invocation, ie, calling a method in the String object referenced by the myStringObject reference variable.
Here I will make a class declaration, then a variable that contains an instance of that class
class MyDataClass {
int i = 5;
}
MyDataClass newInstance = new MyDataClass();
System.out.println(newInstance.i); //references the member 'i' in the object
When you are done working with an object you can set it to a null reference with the null literal...
newInstance = null; //this makes this object eligible for garbage collection.
Basically, with object references you have all the benifits of using pointers without the problems of memory management, and pointer arithemetic to cause you problems.
You won't miss them!
Rob
