In this article, we will explain the procedure for debugging while the Java environment has already been built.
If you haven't built the environment yet, please see the article below for an explanation of the flow. Java development environment construction: Flow from installing OpenJDK 11 to execution
OS: macOS Catalina version 10.15.4 Text Editor: Visual Studio Code-Insiders (VSCode)
Let's debug it now. Open VS Code.
In the above figure, create a file called Hello.java in advance. I am writing the following code.
Hello.java
public class Hello
{
public static void main(String[] args) {
System.out.println("Good morning java!!");
int a = 1;
int b = 3;
System.out.println("The contents of a" + a);
System.out.println("The contents of b" + b);
b = a;
System.out.println("The contents of a" + a);
System.out.println("The contents of b" + b);
}
}
As shown in the figure below, add a red circle mark to the left of the 6th line as a trial. (Click to the left of "6" to add a red circle mark) Then click Debug.
Then the terminal will open and you will see the one surrounded by a green frame.
And then click Step Over Move to the 7th line.
If you click Step Over, I think the 7th and 8th lines will be executed and displayed in the terminal as well.
And when you go to line 10, you'll finally feel like you've benefited from this debugging. Please see the figure below.
The 9th line is executed, You can see the moment when the value of b changes from 3 to 1.
If you go to the last line, you can see that the value of b has been changed and displayed.
WATCH It appears on the left side of VS Code when debugging, This is the ability to keep an eye on the evolution of variable values. It will be displayed all the time when you want to follow the value of a variable.
CALL STACK Displays the history of function call paths.
BREAK POINTS A list of currently set breakpoints (red circles).
How was it? I think that you can get a better understanding by executing debugging while changing various values. Thank you ☕️
Recommended Posts