Backend Development 20 min read

Comprehensive Guide to Using IntelliJ IDEA Debug Features

This tutorial provides a thorough walkthrough of IntelliJ IDEA's Debug functionality, covering preparation, main interface, detailed explanations of service and debug buttons, variable inspection and modification, conditional breakpoints, expression evaluation, frame dropping, force return, multithreaded and Stream debugging, as well as remote debugging techniques.

Top Architect
Top Architect
Top Architect
Comprehensive Guide to Using IntelliJ IDEA Debug Features

Introduction

Debug is one of the most frequently used features in IDEs like IntelliJ IDEA. It allows developers to trace code execution, monitor parameter changes, locate errors, and even explore third‑party frameworks. Once a program is no longer a black box, you can see exactly what happens at each step and why.

Outline of Topics

Preparation

Main Interface Overview

Detailed Explanation of All Function Buttons

Viewing Variables

Changing Variable Values

Setting Conditional Breakpoints

Evaluating Expressions

Rollback Operations

Force Return

Multithreaded Debugging

Stream Debugging

Remote Debugging

Conclusion

Preparation

Before starting the Debug session, ensure you have the following tools ready:

IntelliJ IDEA

The code you want to debug

The example code used throughout this guide is a classic LeetCode problem – the solution to "Two Sum":

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class ToSum {
    public static int[] twoSum(int[] nums, int target) {
        Map
map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int sub = target - nums[i];
            // If the complement already exists, return the pair of indices
            if (map.containsKey(sub)) {
                return new int[]{map.get(sub), i};
            }
            map.put(nums[i], i);
        }
        throw new IllegalArgumentException("No two sum solution");
    }

    public static void main(String[] args) {
        int[] nums = {2, 7, 11, 15};
        int target = 9;
        int[] ints = twoSum(nums, target);
        System.out.println(Arrays.toString(ints));
    }
}

Main Interface Overview

When you start a Debug session, the main window shows several key areas:

Debug: Starts the Debug mode.

Breakpoint: Click the left gutter to set a breakpoint; execution will pause here.

Service Buttons: Controls to stop, start, edit configurations, and more.

Debug Buttons: Includes Show Execution Point, Step Over (F8), Step Into (F7), Force Step Into, Step Out, Drop Frame, Run to Cursor, Evaluate Expression, Trace Current Stream Chain, etc.

Frames: Shows the call stack of the current thread. You can hide library frames via the funnel icon.

Variables: Displays current variable values and allows editing.

Watches: Lets you monitor selected variables across the whole debugging session.

Debug Window Position: You can dock the Debug window to any side or make it a floating window.

Viewing Variables

There are four ways to view variable values:

Enable the Settings option to show values directly in the editor.

Hover the cursor over a variable to see its current value.

Open the Variables pane to see all in‑scope variables.

Drag a variable from Variables to the Watches pane for persistent monitoring.

Values can also be edited directly in the Variables pane by selecting Set Value… and pressing Enter.

Changing Variable Values

Besides editing in the Variables pane, you can modify a variable via the Watches pane or by using the Set Value… action. For example, changing nums[0] from 2 to 22 is reflected immediately.

Setting Conditional Breakpoints

When iterating over large collections, you can add a condition to a breakpoint so that execution only stops when the condition is true. For instance, setting the condition n == null will pause only when n is null.

Evaluating Expressions

The Evaluate Expression… feature lets you compute arbitrary expressions in the current context without restarting the program. Example: evaluating map.keySet() or any complex expression while paused.

Rollback Operations

The Drop Frame button acts as a "rewind" feature, allowing you to return to the previous method call. Note that state changes (e.g., database updates) cannot be undone; only the call stack is reset.

Force Return

If you have identified a bug and want to stop further execution without affecting the whole service, use Force Return to provide a custom return value (e.g., new int[]{2, 7} ) or throw an exception.

Multithreaded Debugging

By default, Debug blocks all threads except the current one. To debug without halting other threads, enable the multithreaded mode in the View Breakpoints dialog and select the desired thread scheduling strategy.

Stream Debugging

When debugging lambda streams, the Trace Current Stream Chain button becomes active if a breakpoint is set inside the stream pipeline. It visualizes each transformation step and the intermediate results, with split‑mode view for step‑by‑step inspection.

Remote Debugging

For bugs that only appear in production, you can attach a remote JVM to IntelliJ IDEA. Add the following JVM argument when starting the remote service:

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar your-app.jar

Then configure a Remote JVM Debug configuration in IDEA with the remote host IP and port (e.g., 5005). After launching the remote process, run the configuration locally in Debug mode; breakpoints will trigger on the remote service.

Conclusion

All essential aspects of IntelliJ IDEA's Debug tool have been covered, from basic setup to advanced features like conditional breakpoints, expression evaluation, frame dropping, multithreaded and Stream debugging, and remote debugging. Mastering these techniques can greatly improve debugging efficiency and overall code quality.

debuggingJavaprogrammingIntelliJ IDEAide
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.