A debugger helps you understand what a program actually does. It pauses execution at selected lines, lets you run instructions manually, and shows how data changes. It is useful for finding faults and understanding unfamiliar logic, but it is only one of several investigation techniques. section 1.1 section 2.0
A practical debugging workflow:
- Read the code first and identify the earliest instruction you need to understand. Set a breakpoint there, then run the app with the debugger. section 2.2
- When execution pauses, inspect the variables in scope and use the execution stack to see where you are and how you got there. Evaluate expressions or use watches to explore values. section 2.2
- Step over an instruction to continue in the current method; step into it when you need to examine its details. Prefer stepping over when possible, so the investigation stays focused. section 2.4
- After stepping into a method, read its code. If it is clear, step out; otherwise, identify the first unclear instruction and investigate from there. section 2.4
Investigating a decoder
A Java decoder loops through strings, extracts digits from each one, and adds them to a total. If the extractor’s behavior is unclear, place a breakpoint on the line that constructs it and calls extractDigits(). Run the app, inspect the current input and variables, and step into the call if you need to see how it works. Compare what you observe with what you expected rather than relying on the method name alone. section 2.1 section 2.2
Listing 2.2 A piece of code we want to understand
public class Decoder {
public Integer decode(List<String> input) {
int total = 0;
for (String s : input) {
var digits = new StringDigitExtractor(s).extractDigits();
total += digits.stream().collect(Collectors.summingInt(i -> i));
}
return total;
}
}
Use the decoder listing to locate the extraction call and follow how its result contributes to the total. section 2.2
A debugger works best once you know where to start. If the relevant logic is hidden in a large app, a profiler can help identify code in execution before you choose a breakpoint. Also, pausing a multithreaded app can change its behavior, making the original problem harder to observe. Combine techniques when a debugger alone does not reveal the cause. section 1.2.1 section 2.2







