NullPointerException

In Java, NullPointerException is a runtime exception and it is thrown when the application try to use an object reference which has a null value. 
When you declare a variable of primitive type, such as int x, the variable x is an int and Java will initialize it to 0 for you. When you assign it the value of 10, 10 is written into the memory location referred to by x.
When you declare a variable of reference type, such as Integer y,  the variable y contains a pointer (because the type is Integer which is a reference type). Since you have not yet said what to point to, Java sets it to null, which means "I am pointing to nothing". The new keyword is used to instantiate (or create) an object of type Integer, and the pointer variable y is assigned to that Integer object.
The NullPointerException occurs when you declare a variable but did not create an object and assign it to the variable before trying to use the variable (called dereferencing). So you are pointing to something that does not actually exist.
<pre><code>
int x;
x = 10;
Integer y;
y = new Integer(10);

public void doSomething(SomeObject obj) {
   //do something to obj
}
doSomething(null);
</code></pre>