Caution: VS Code guides section is a work-in-progress, containing content contributed by students.
This tutorial covers the basics of using VS Code’s debugger for Java features.
If you are new to using an IDE-based debugger, we recommend watching the video below for an introduction to the features of VS Code Java debugger.
To recall how to use a specific feature, you can refer to the sections below.
Need help with following prerequisites? Check out our Preparing VS Code for Java guide first.
Purpose: A breakpoint is a line in the code at which the debugger will pause the execution.
How: Click in the left margin next to the line of code where you want to set the breakpoint. A red dot will appear in the margin.
[image credit: VS Code Docs]
Video segment 0.30 - 0.50 :
More info from VS Code Docs is here.
Purpose: To get VS Code to run the code in the debugger mode, so that the debugger can direct the execution flow as needed by the debugging.
How: There are multiple ways to run and debug your Java application using the extension. One way is to click on the dropdown arrow beside the play icon (top editor title bar) and select Debug Java
[image credit: VS Code Docs]
Video segment 0.44 - 1.10 :
More info from VS Code Docs is here.
Purpose: To examine values of variables at different steps of the execution
How: Use the Debug Console panel at the bottom of the window. At each breakpoint, you can see:
[image credit: VS Code Docs]
Video segment 1.10 - 1.48 :
More info from VS Code Docs is here.
Purpose: To move through code line by line and observe how it is executed
How: Click the Step Over button (curved arrow) in the debug toolbar, or press F10
[image credit: VS Code Docs]
Video segment 1.54 - 2.09 :
More info from VS Code Docs is here.
Purpose: To enter a method being called on the current line to see how it behaves
How: Click the Step into button (down arrow), or press F11
[image credit: VS Code Docs]
Video segment 2.09 - 2.13 :
More info from VS Code Docs is here.
Purpose: To finish executing the current method and return to its caller, without stepping through the rest of it.
How: Click the Step out button (up arrow), or press Shift+F11
[image credit: VS Code Docs]
Video segment 2.13 - 2.22 :
More info from VS Code Docs is here.
Purpose: To pause the execution at a certain breakpoint only when a certain condition is met (E.g. when i == 100)
How:
[image credit: VS Code Docs]
More info from VS Code Docs is here.
Purpose: Allows you to compute the value of an expression at a specific point during execution, enabling dynamic inspection of variables and data structures.
How: Enter through the WATCH window, or the Debug Console
More info from VS Code Docs is here.
Contributors: Sulaksha Muthukrishnan (@crmlatte)