IDE (eclipse) debug execution, step execution (Java)


This article is a record of what I understand for those who are currently studying Java.

In many cases, Java code is debugged and executed in an integrated development environment, and the operation is confirmed by step execution, so I will describe the series of steps.

Install eclipse

Install eclipse, which is currently free to use in a Java integrated development environment. You can download it from the link below.

Select the latest version of eclipse 2020 at this time.

スクリーンショット 2020-05-15 10.17.48.png

Then the screen of the following image will appear. This time I will install it according to my environment. Since it is a 64-bit CPU on a Mac and a Java environment is required, select the red frame below.

スクリーンショット 2020-05-15 10.27.14.png

You will be taken to the download page and the download will start automatically. After downloading, open the file and move it to the application.


Creating a class for debugging

You have now installed it on your Mac. Let's start it immediately. Then a screen like the image will be displayed, so select Create Java Project.


If you select Create, the image screen will appear. This time I want to run the Java file and debug it, so just enter the project name and you're done.


When you're done, your project will be created, so let's create a class within the project. Right-click and select New, Class to display the creation screen.


When the creation screen is displayed, name it Main and check public static void main (String args []) to complete.


Now that the class is created, enter the following code into the eclipse editor.

public class Main{
    int instans = 60;
    static int global = 95;

    static void debug(){
        System.out.println("Debug execution");

    void print(){

    public static void main(String args[]){
        System.out.println("main start");

        int x = 50;

        String str = "Character type";

        Main m = new Main();

        x = 100;

        str = "Character type conversion";


        System.out.println("main end");

Let's debug this code and see how it works.


From here, you can start debugging, but in order to run debugging, you must first specify where to stop the program. That is called a breakpoint. Let's actually set a breakpoint in eclipse.

System.out.println("main start");

This time, set a breakpoint at the above location. Right-click on the left side of the number of lines of code above in the eclipse editor to bring up the menu and select Toggle Breakpoint.


Since you can debug with this setting, select the bug mark on the upper left of eclipse. Debug execution starts here.


This will launch the debug function. And the processing is stopped at the breakpoint set earlier. Therefore, the output of "debug execution" that operates before the breakpoint is output, and the f "main end" below is not output. Therefore, you can see that the process is stopped at the breakpoint placed between the two processes.


Step execution

Up to this point, we have stopped processing, but let's perform step execution that advances processing line by line. Click the step over button in the continuation of the above.


After clicking, the stopped process is executed on one line, and the selected state is reflected on the next line. Breakpoint

System.out.println("main start");

Since one line was executed by step execution, main start is displayed in the output column.


Now that you have an image of step execution that moves line by line, let's press the step over button twice to proceed. There is a list of variables on the right side of the editor, but the contents have been updated.


Variables are defined and initialized by performing two step executions.

int x = 50;
String str = "Character type";

By passing these two processes, the value of the variable currently held can be displayed. Click the stepover button three more times to proceed.


There is a process in which the values of variables x and str are updated by performing step execution three times.

x = 100;
str = "Character type conversion";

Therefore, the current value of the variable list has been updated.

By the way, the variable m is defined in the interim process, and the created instance is assigned.

Main m = new Main();

The Main class has an instance variable instance, so you can see that it is also defined. Click the right arrow for the variable name m in the variable list.


You can also check the instance variables like this. By the way, the static variable is not displayed because the static variable is an independent element and the variable m does not have it, so it is not displayed.

At the end

In this article, I described the procedure to debug execution in the IDE and check the operation line by line in the important step execution.

Since you can see the state of the value at the time when the program is watching during execution, you can check whether the value you intended is entered at any time when checking the operation, so incorporate debug execution How about trying it?

Recommended Posts

IDE (eclipse) debug execution, step execution (Java)
Java debug execution [for Java beginners]
java Eclipse How to debug javaScript
2017 IDE for Java
Java (eclipse) installation procedure
Java instruction execution statement
Eclipse ~ Java project creation ~
Is Eclipse IDE dying?
To debug in eclipse
Parallel execution in Java
Null-safe program in Java (Eclipse)
Java development environment (Mac, Eclipse)
[Java] Spring AOP execution order
Java tips --Spring execution Summary
First Java development in Eclipse
External process execution in Java