When does a NullPointerException get thrown in java?

Java 8Object Oriented ProgrammingProgramming

A null pointer exception is thrown Whenever you try to

  • Call the instance method of a null object.
  • Access, modify, print, a null value.
  • Trying to access (print/use in statements) the length of the null value.
  • Throw a null value.
  • Access an element of an array without initializing it.

Then, a Null Pointer Exception will be thrown.

Published on 09-Jan-2018 12:13:20