Skip to content
Ameen Abozaid
BEG-018

Debugging

  • 6 Lessons
  • 71 min of reading
  • 3 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Breakpoints
  • step into/over/out
  • variable inspection
  • stack traces
  • common errors

Learn first

71 min of reading · 3 h of practice (estimate)

Learning outcomes

  1. Set breakpoints (including conditional ones) and step into, over, and out in IntelliJ.
  2. Inspect and watch variables to find where actual behavior diverges from expected.
  3. Read a stack trace and navigate to the failing line.
  4. Apply a systematic process: reproduce, isolate, hypothesize, test, fix, verify.

Lessons

  1. 01A method for debugging12 min read
  2. 02Breakpoints and stepping12 min read
  3. 03Variables, watches, and evaluate expression12 min read
  4. 04Reading stack traces12 min read
  5. 05A catalog of common runtime errors12 min read
  6. 06Demo: a full bug hunt from report to fix11 min read

Lab and exercises

Lab

BEG-018-LAB1 · Bug hunt

Outcomes: 1–4 · Time: ~2 h You receive five small programs, each with one logic bug. For each, write a trail:

  1. Reproduction steps (input, expected, actual).
  2. Your hypothesis.
  3. The line found with the debugger (breakpoint, stepping, watches).
  4. The fix and how you verified it.

Acceptance: all five fixed with a written trail.

Exercises (assessment: live debugging demonstration, also part of the BEG graduation gate)

IDOutcomeTask
BEG-018-EX011Set a conditional breakpoint that stops only on iteration 50 of a 100-iteration loop, then step into, over, and out of a method call.
BEG-018-EX022Using watches, find where sum first differs from your hand-traced value in a given program.
BEG-018-EX033Read a provided stack trace: name the exception, the failing line, and the calling method.
BEG-018-EX044Write the six-step debugging process and apply it to "average prints the wrong value for [1, 2]".
BEG-018-EX053Match three exceptions (NullPointerException, NumberFormatException, ArithmeticException) to code that causes each.
Show solutions
  • EX01 Right-click the breakpoint, enter i == 49 (or i == 50 depending on the loop start); use F8, F7, Shift+F8.
  • EX02 Add a watch for sum; compare it with your trace table on each pass; the first mismatch is the clue.
  • EX03 Read the first line for type and message, then the first line with your own class and its line number.
  • EX04 Reproduce with [1, 2]; isolate the average method; hypothesis integer division; test with a debugger watch; fix with (double) sum / count; verify with [1, 2] and [2, 4, 6].
  • EX05 String s = null; s.length(); Integer.parseInt("abc"); 5 / 0.
  • Outcome 4 is also assessed by the live debugging demonstration and the lab written trails.

Quiz

Outcomes: O1 breakpoints and stepping · O2 inspecting variables · O3 stack traces · O4 debugging process.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1A breakpoint:O1
  2. 2"Step into" does what?O1
  3. 3A conditional breakpoint pauses:O1
  4. 4A watch is used to:O2
  5. 5When a variable's value surprises you, you should:O2
  6. 6In a stack trace, which line do you open first?O3
  7. 7Index 5 out of bounds for length 5 means:O3
  8. 8Integer.parseInt("abc") throws:O3
  9. 9The correct order is:O4
  10. 10Fixing the symptom rather than the cause means:O4

Practical part

Five exercises BEG-018-EX01 to EX05 plus the five-bug hunt with written trails; the live debugging demonstration (also part of the BEG graduation gate) is assessed by the instructor. Pass: all five bugs fixed with trails and a successful live demonstration.

Common mistakes

Changing code at random; adding print statements everywhere instead of breakpoints; fixing the symptom, not the cause.

Assessment

Live debugging demonstration (also part of the BEG graduation gate).

Career relevance

Grows into troubleshooting (JNR-054), profiling (MID-008), and incident handling (MID-050).

Type to search levels, phases, modules and lessons.