9 Years
Discussion Span
Last Post by PoovenM

I don't quite grasp what you're trying to ask. But basically all objects have some reference or pointer to the heap (memory handled by Windows). Objects would be those entities created using the new operator. A null exception is flagged whenever a variable is declared but not instantiated. Consider:

Tokenizer t;

Here we introduce the variable t for the first time. At this time it points to nothing or null. This simply means that it doesn’t point to an object in the heap either because we removed the link or we didn’t create on in the first place. By doing:

t = new Tokenizer(“Hello World!”);

we create an object in the heap an set a reference or pointer to that object via the variable t . This pointer is sort of like a memory position but it isn’t accessible to you. In C++ it is accessible, Java hides pointer to make for cleaner (but slower) programs. Oh, the following code will have the effect of deleting the object from the heap:

t = null;

well really it just says to the garbage collect, I don’t need that object, remove it from the heap when you’re free. So we're saying t points to nothing again. Hope that adds clarity.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.