Fundamentals 16 min read

Master IntelliJ IDEA Debugging: From Basics to Advanced Techniques

This guide walks you through every essential feature of IntelliJ IDEA's Debug tool—pre‑setup, main UI, service and debug buttons, watches, variable inspection, conditional breakpoints, expression evaluation, frame rollback, force return, multithreaded, Stream and remote debugging—empowering you to troubleshoot Java code efficiently.

Java Interview Crash Guide
Java Interview Crash Guide
Java Interview Crash Guide
Master IntelliJ IDEA Debugging: From Basics to Advanced Techniques

Preparation

Before using the Debug feature you need IDEA installed and a piece of code to debug. The example used throughout is a classic LeetCode "Two Sum" solution.

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

public class ToSum {
    public static int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int sub = target - nums[i];
            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

The Debug window contains several panels:

Debug: start debugging.

Breakpoint: click the left gutter to set a breakpoint; execution stops there.

Service Buttons: control the debug session (run, pause, stop, view breakpoints, mute breakpoints, thread dump, settings, pin tab, etc.).

Debug Buttons: 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.

Frames: call stack of the current thread (filterable).

Variables: current variable values, editable.

Watches: user‑defined expressions that stay visible across steps.

Service Buttons Details

Rerun ‘xxx’: restart the program in Debug mode.

Edit Run Configuration: modify JVM options, environment variables, or set up remote debugging.

Resume Program (F9): continue execution until the next breakpoint.

Pause Program: pause a long‑running step or a dead loop.

Stop ‘xxx’ (Ctrl+F2): terminate the debug session.

View Breakpoints: list and configure all breakpoints (conditions, thread filters, etc.).

Mute Breakpoints: disable all breakpoints temporarily.

Get Thread Dump: export the current stack trace.

Settings: toggle display of values, return values, etc.

Pin Tab: fix the Debug tool window in place.

Debug Buttons Details

Show Execution Point: highlight the line currently being executed.

Step Over (F8): move to the next line, skipping over called methods without breakpoints.

Step Into (F7): dive into a called method even if it has no breakpoint.

Force Step Into: force entry into any method, useful for library code.

Step Out (Shift+F8): exit the current method and return to the caller.

Drop Frame: roll back execution to the selected stack frame (the "undo" button).

Run to Cursor: continue execution until the cursor position, without setting a breakpoint.

Evaluate Expression…: compute arbitrary expressions in the current context.

Trace Current Stream Chain: visualize each step of a Java Stream pipeline.

Watches Panel

Watches let you monitor specific variables or expressions. You can add a new watch, remove it, move it up or down, duplicate it, or show watches in the Variables tab.

Viewing and Changing Variable Values

Variable values appear inline in the editor (grey text) and in the Variables panel. You can edit a value directly via Set Value…, which updates the running program without restarting.

Conditional Breakpoints

Set a breakpoint condition so execution stops only when a specific expression evaluates to true (e.g., stop when a collection element is null).

Evaluating Expressions

Use Evaluate Expression… to run arbitrary code snippets such as map.keySet() or complex expressions without modifying the source.

Rollback (Drop Frame)

Drop Frame re‑executes the selected method call. It cannot revert external side effects (e.g., database changes) but is useful for re‑testing logic.

Force Return

The Force Return action lets you supply a return value (or throw an exception) to exit the current method early.

Multithreaded Debugging

By default Debug pauses all threads. You can enable "debug only the thread that hits a breakpoint" so other threads continue running, and switch between threads in the Frames view.

Stream Debugging

When a breakpoint is set inside a Stream pipeline, the Trace Current Stream Chain button shows each intermediate transformation and result, with a split‑mode view for step‑by‑step inspection.

Remote Debugging

To debug code running on a remote server, start the JVM with

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

(choose an unused port). In IDEA create a "Remote JVM Debug" configuration, specify the host IP and port, and launch the remote process. Then attach the local debugger; breakpoints work as if the code were local.

Conclusion

All essential IDEA Debug features have been covered, from basic UI navigation to advanced techniques like conditional breakpoints, expression evaluation, frame rollback, force return, multithreaded, Stream, and remote debugging.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaIntelliJ IDEAIDEremote debuggingVariable Inspection
Java Interview Crash Guide
Written by

Java Interview Crash Guide

Dedicated to sharing Java interview Q&A; follow and reply "java" to receive a free premium Java interview guide.

0 followers
Reader feedback

How this landed with the community

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.