1Z0-811 Exception Handling and Development Tools Practice Question
A developer is debugging a Java application that throws a NullPointerException. Which two actions help identify the source of the exception? (Choose two.)
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use a debugger to step through code
To identify the source of a NullPointerException, the most effective actions are examining the stack trace (option C) and using a debugger (option B). The stack trace shows the exact line number and method call sequence where the exception occurred, pinpointing the location. A debugger allows you to step through code, inspect variable states, and observe the flow leading to the null reference. While System.out.println (A), catching the exception and printing its message (E), and recompiling with -g (D) can provide debugging information, they are not as direct or efficient for locating the root cause; notably, catching the exception does not prevent it and only prints the message without full stack details.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use System.out.println statements
Why it's wrong here
Print statements require code changes and recompilation, and they may not always capture the exact moment of the exception.
- ✓
Use a debugger to step through code
Why this is correct
A debugger allows setting breakpoints and stepping through code to inspect variable values and find where the null reference occurs.
- ✓
Examine the stack trace
Why this is correct
The stack trace shows the method call hierarchy and line numbers, directly pinpointing the null reference.
- ✗
Recompile with -g flag
Why it's wrong here
The -g flag adds debugging information to class files, but by itself it does not identify the source; it only improves stack trace output.
- ✗
Catch the exception and print its message
Why it's wrong here
Catching the exception and printing its message only shows the exception type and message, not the exact location.
Go deeper
Related to this question
About these practice questions
One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.