IDE Debugging
Master breakpoints, stepping, and variable inspection to find and fix bugs like a professional Java developer.
What Is Debugging?
Debugging is the process of finding and fixing errors (bugs) in your code. Instead of guessing where things go wrong, a debugger lets you pause your running program and examine it from the inside: line by line, variable by variable.
Why Not Just Use Print Statements?
Adding System.out.println() everywhere is a common beginner strategy. It works for simple cases, but it has major drawbacks compared to a real debugger.
The Three Core Concepts
Setting Breakpoints
A breakpoint is a marker you place on a line of code. When the program reaches that line during execution, it pauses before executing it. You click in the gutter (the left margin) of your editor to toggle a breakpoint.
Stepping Through Code
Once paused at a breakpoint, you can advance execution one line at a time. There are three main stepping commands:
Step Over vs Step Into
Inspecting Variables
While paused, the IDE shows you the current value of every variable in scope. This is the Variables panel (also called Watches). You can also hover over any variable in the editor to see its value.
The Debug Workflow
Example: Off-by-One Bug
This method should print numbers 1 through 5, but something is wrong. Let's debug it.
Example: NullPointerException
The program crashes with a NullPointerException. Let's set a breakpoint and find the null variable.
Example: Logic Error in a Loop
This method should compute the average of an array but gives the wrong answer. Let's trace it.
The Debug Toolbar
Every Java IDE (IntelliJ, Eclipse, VS Code) provides a toolbar with these controls once you are in debug mode:
How to Apply This
Common Mistakes
Debugging Cheat Sheet
| Action | What It Does | When to Use |
|---|---|---|
| Set Breakpoint | Marks a line to pause at | Before suspicious code |
| Resume | Continues to next breakpoint | Done inspecting this area |
| Step Over | Executes current line, moves next | Method calls you trust |
| Step Into | Enters the called method | Method gives wrong result |
| Step Out | Finishes current method, returns | Stepped in too deep |
| Inspect Variable | Shows current value | Every step: compare expected vs actual |
| Evaluate Expression | Runs any expression live | Test a fix before editing code |
Question 1 of 5
What happens when your program reaches a line with a breakpoint during debugging?
Question 2 of 5
You are paused at a line that calls calculateTotal(). You suspect the bug is inside that method. Which stepping command should you use?
Question 3 of 5
You accidentally stepped into a library method you don't need to debug. Which command returns you to your code?
Question 4 of 5
A student writes this code to convert a string to uppercase, but the program crashes with a NullPointerException:
The student sets a breakpoint at Line 2 and runs in debug mode.
What will the Variables panel show for s when the debugger pauses at Line 2?
Question 5 of 5
What is the main advantage of using an IDE debugger over adding System.out.println() statements?