Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Question: What is the purpose of the 'NullPointerException' in Java?
Answer: The 'NullPointerException' is thrown when attempting to access or modify an object reference that is null.

Example:

String str = null;
int length = str.length(); // This will throw NullPointerException
Is it helpful? Yes No

Most helpful rated by users:

©2025 WithoutBook