Master IntelliJ IDEA Debugging: Step-by-Step Guide to Breakpoints, Expressions, and Thread Control
This comprehensive guide explains how to use IntelliJ IDEA's Debug mode—including launching the debugger, managing breakpoints, inspecting variables, evaluating expressions, employing smart step‑into, configuring conditional breakpoints, handling multithreaded debugging, and using drop‑frame and force‑return features—to efficiently trace and troubleshoot Java applications.
Debug Overview
Debugging tracks a program's execution flow, helping locate exceptions and observe parameter changes. Enabling Debug mode in IntelliJ IDEA allows you to step through code, inspect variables, and understand third‑party framework internals.
1. Debug Interface
The Debug tool window displays eight key areas (illustrated in the screenshots):
Start in Debug mode : Use the left button to launch the application directly in Debug mode.
Breakpoint : Click the gutter or press Ctrl+F8 to toggle a breakpoint; colors are configurable.
Debug window : Activates automatically when execution hits a breakpoint (can be forced in settings).
Debug buttons : Eight buttons provide core actions (hover to see shortcuts). The same actions are available under the Run menu.
Service button : Controls start/stop of the service and breakpoint management.
Method call stack : Shows all methods on the current thread; enable Show All Frames to include library calls.
Variables : Displays variables in the current frame.
Watches : Drag variables here or create new watches to monitor specific values.
Ensure the Debug window auto‑opens by checking Show debug window on breakpoint in the settings.
2. Basic Usage & Shortcuts
The first button group (8 buttons) includes:
Show Execution Point (Alt+F10) : Jump to the current execution line.
Step Over (F8) : Move to the next line without entering called methods.
Step Into (F7) : Enter the method on the current line (skips library code).
Force Step Into (Alt+Shift+F7) : Enter any method, including library code.
Step Out (Shift+F8) : Exit the current method back to its caller.
Drop Frame (default none) : See section 8 for details.
Run to Cursor (Alt+F9) : Execute until the cursor line without setting a breakpoint.
Evaluate Expression (Alt+F8) : Open the expression evaluator (see section 4).
The second button group (7 buttons) includes:
Rerun : Restarts the application.
Update Application (Ctrl+F5) : Hot‑swap changed classes/resources (often used with JRebel).
Resume Program (F9) : Continue execution to the next breakpoint.
Pause Program : Pauses execution (rarely needed).
Stop (Ctrl+F2) : Terminates the process; may require killing lingering JVMs.
View Breakpoints (Ctrl+Shift+F8) : Opens the breakpoint manager.
Mute Breakpoints : Disables all breakpoints; toggle to re‑enable.
3. Variable Inspection
During debugging you can view variable values in several places:
Inline hints next to the code line.
Hover over a variable to see its current value and click for details.
The Variables pane lists all locals in the current frame.
The Watches pane lets you add custom expressions or drag variables from the Variables pane.
4. Evaluating Expressions
Press Alt+F8 or click the Evaluate Expression button to open a dialog where you can type any Java expression—variables, parameters, or method calls—and see the result without adding print statements. You can also modify variable values directly in this dialog.
5. Smart Step‑Into
When a line contains multiple method calls, Smart Step Into (Shift+F7) lists the candidate methods; selecting one jumps directly into that method, saving you from stepping through unwanted calls.
6. Conditional Breakpoints
Set a breakpoint condition (e.g., exist == true) so the debugger stops only when the condition evaluates to true. Use the breakpoint manager to add log messages, evaluate and log expressions, or filter by instance or class. The Pass count option stops after a specified number of hits, useful for loops.
7. Multithreaded Debugging
By default IntelliJ blocks all threads (ALL) during debugging. Change the thread policy in the breakpoint settings to allow other threads to run. Use the Frames dropdown to switch the current thread view.
8. Drop Frame (Rollback)
Rollback lets you return to the start of a previous method call:
Drop Frame button : Steps back through the call stack, optionally hiding library frames.
Alternatively, right‑click a stack frame and choose Drop Frame , then press F9 to resume from that point.
Note: State changes (object mutations, DB updates) are not reverted.
9. Force Return (Interrupt Debug)
If you need to abort the current request, use Force Return . In the dialog, provide a return value (e.g., results or new HashMap<>()) to exit the method early and skip the remaining logic.
These techniques together enable efficient debugging of Java applications within IntelliJ IDEA.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
