how can v explain null value

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.