null can be used when you must specify an argument in a particular place but don’t have any.

Java includes a value that isn’t anything: null. It refers to a memory address that has not been assigned. In Java terms, that means it refers to an object or primitive that has not been created. As I mentioned in the “Arrays” section, when you create an array without specifying its values, you are creating a collection of null values. They have no memory address, no corresponding primitive or object exists for them, and so they are null. That might sound like a problem, and the whole concept of null often causes novice programmers some trouble. You can keep it straight by remembering that a null is a non-existent reference.

Java 7 for Absolute Beginners

Sponsored content