NullPointerException
means that the variable doesn't hold any reference to a object. What I mean by reference is, For ex:
String path="";
File f=new File(path);
if(f.exists()) {
// do something
}
f is a variable of type File which holds a reference to a object File defined by path
and now you can use variable f just like any other variable call methods on that variable etc.
Another example
File f;
if(f.exists()) {
// do something
}
Now you will get NullPointerException in line if(f.exists())
because f doesn't hold any reference.
In JAVA new
keyword is used to assign new reference. JVM will take care of all the low level details. It is similar to pointers in c and c++. In JAVA you don't have to explicitly delete the objects. JVM garbage collector will take care of these things. Java is object oriented language
Do read and understand OOP comcepts