Java debug execution [for Java beginners]

Introduction

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)

Debug execution

Let's debug it now. Open VS Code.

スクリーンショット 2020-05-13 11.29.29.png

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.

スクリーンショット_2020-05-13_11_34_51.png

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. スクリーンショット_2020-05-13_11_49_04.png

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. スクリーンショット_2020-05-13_11_56_27.png

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. スクリーンショット_2020-05-13_13_10_15.png

A little supplement

スクリーンショット_2020-05-14_15_01_19.png If you press this "Step into" that appears when you are debugging, The class file to which the method to be executed belongs is opened and executed step by step. If you want to exit from the place you entered with "Step into", you can exit with "Step out".

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

Java debug execution [for Java beginners]
[Java] Basic statement for beginners
Java for beginners, data hiding
Java application for beginners: stream
[For beginners] Summary of java constructor
Rock-paper-scissors game for beginners in Java
Java for beginners, expressions and operators 1
[For beginners] Run Selenium in Java
Java for beginners, expressions and operators 2
IDE (eclipse) debug execution, step execution (Java)
[For Java beginners] About exception handling
Classes and instances Java for beginners
Learn Java with "So What" [For beginners]
[For beginners] Difference between Java and Kotlin
2017 IDE for Java
Java for statement
[For beginners] How to debug in Eclipse
Kantai Collection Java # 1 Classes and Objects [For Beginners]
A collection of simple questions for Java beginners
[Introduction to Java] Basics of java arithmetic (for beginners)
Let's use Java New FileIO! (Introduction, for beginners)
[Java] for statement, while statement
Java instruction execution statement
[Java] Package for management
[Java] for statement / extended for statement
Countermeasures for Java OutOfMemoryError
NLP for Java (NLP4J) (2)
(Memo) Java for statement
NLP for Java (NLP4J) (1)
Parallel execution in Java
Scraping for beginners (Ruby)
[For beginners] Quickly understand the basics of Java 8 Lambda
[For beginners] How to operate Stream API after Java 8
[For beginners] Minimum sample to display RecyclerView in Java
Java development for beginners to start from 1-Vol.1-eclipse setup
Introduction to Java for beginners Basic knowledge of Java language ①
List of frequently used Java instructions (for beginners and beginners)
Java update for Scala users
[Java] Precautions for type conversion
Books used for learning Java
[Java] Beginner's understanding of Servlet-①
[For super beginners] DBUnit super introduction
2018 Java Proficiency Test for Newcomers-Basics-
Object-oriented summary by beginners (Java)
(For beginners) [Rails] Install Devise
[For beginners] About the JavaScript syntax explained by Java Gold
[For super beginners] Ant super introduction
[Java] Spring AOP execution order
More usable Enumerable for beginners
Java thread safe for you
Java tips --Spring execution Summary
[Java] Summary of for statements
[Java] Tips for writing source
Java beginners read Hello World
External process execution in Java
Java installation location for mac
Introducing Spring Boot2, a Java framework for web development (for beginners)
For Java beginners: List, Map, Iterator / Array ... How to convert?
[For super beginners] Maven super introduction
Java while and for statements
Kantai Collection Java # 0 What is Object Oriented Programming (OOP)? [For beginners]