Understanding null in Java


In Java, null is a special value that can be assigned to an object reference. null indicates that the reference does not point to any object.

Source Code

String str = null; // str does not reference any object
if (str == null) {
    System.out.println("str is null.");
}

Check for null before invoking methods on object references to avoid NullPointerException.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments