This post originated from an RSS feed registered with Java Buzz
by Javin Paul.
Original Post: What is NullPointerException in Java - Why When and How
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
NullPointerException in Java is a unchecked
Exception defined in java.lang package and comes when a member
of a an object either field or method is called on a object which is null. null
is a keyword in Java which means nothing and calling method on Object whose
value is null will result in NullPointerException. Since
default value of Object
is null, if you call any method or access any field on an Object which is not initialized will throwNullPointerException. Some programmer get
confused with name as well, Since Java does not support pointers, How can you
have NullPointerException in Java? Well java.lang.NullPointerException
doesn't have anything to do with pointers, it just an Exception in Java.
If you look at it more deeply, NullPointerException is an unchecked
Exception and it's not mandatory to provide Exception handling code for it
using try, catch and finally. In fact most of NullPointerException
comes because of programming errors. See most common
cause of NullPointerExceptionto find out
most common scenario where NullPointerException comes in
Java. In this Java article we will not only see What is NullPointerException
but also How to avoid NullPointerException and How to
fix java.lang.NullPointerException in Java.