
What is a java.lang.NullPointerException? Why do we use this exception class and when it occurs in any java program? Is this extends from exception class of Java?

Java null pointer exception handling
What is Java NullPointerException? In Java NullpointerException is a RuntimeException and occurs when it confronts a null variable where an object is required. Java nullpointerexception never provide details on exception occurrences, it just returns the line number that occres it. So, it's required to go through entire variables to track the null one.
Given is the Java Class NullPointerException Tree
java.lang.Object --> java.lang.Throwable --> java.lang.Exception --> java.lang.RuntimeException--> java.lang.NullPointerException
Handling NullPointerException in Java:
java.lang.NullPointerException occurs when it tries to invoke a null object, at the time of modifying null value or obtaing a null value in an arrray. To handle null pointer exception, you must discourage passing and returning of null parameters and impose check method arguments for Null values.
Try and catch block can also prove helpful in handling null exceptions.
Example of NullPointerException:
try {
int z= array1.length;
} catch(final IOException|NullPointerException ex) {
// This Nested catch works with Java 7 and above
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.