Why is NullPointerException in Java?

Java 8Object Oriented ProgrammingProgramming

NullPointerException is a runtime exception and it is thrown when the application try to use an object reference which has a null value.

For example, using a method on a null reference.

Object ref = null;
ref.toString(); // this will throw a NullPointerException
Updated on 25-Feb-2020 05:02:26