简体   繁体   中英

Run or Debug when using Eclipse?

What's the difference between the debug button and the run button in eclipse? I'm currently working on 2D games with java, but I realized that I'm not entirely sure whether I should click debug or run. Is there an advantage to using one over the other?

Thanks!

Debug will execute a lot slower than a regular Run. Eclipse will only recognize breakpoints when you are running in Debug. You should use Debug when you are testing your game.

You can also look at variables in real time while you are debugging. You can pause execution and you can look at all running threads, it is really quite useful when it is used properly.

Here is a pretty good tutorial on debugging if you are interested:

Run and debug are two totally different animals. If you do not know what the debug button does then you should be hitting the run button as debug will drastically slow down your program testing.

Now you might ask, but I want to use the debugger. Okay here is a simple way to demonstrate the usefulness of the debugger. Place this code in a new project in Eclipse.

int n = 0;
for(int i = 0; i<10;i++)
{
System.out.println("I am printing "+n++);
}

Click on the int = 0; line and press CTRL+SHIFT+B you will notice a small dot will appear to the left of the line. Then run as debug and it will stop your program at this point. From here you can keep pressing f6 to "step through" your program. You can toggle breakpoints wherever you want.

Then press Window > Show View > Other and type Variables, select that. 窗口>显示视图>其他 In the new box that pops up you will see buttons on the top click the one that says Open New View when you highlight it 打开新视图

This will open up a variable window that will show you the variables in the part of the program you are stepping through After you press f6 two or three times with my example above you should get this.. 变量视图 Not only can you see the variables change as you press f6 but you can actually double click on the value column and change the values in run-time to ask what if questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM