简体   繁体   English

使用Eclipse时运行还是调试?

[英]Run or Debug when using Eclipse?

What's the difference between the debug button and the run button in eclipse? 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. 我目前正在使用Java进行2D游戏,但是我意识到我不确定是否应该单击“调试”或“运行”。 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. 当您在Debug中运行时,Eclipse仅会识别断点。 You should use Debug when you are testing your game. 测试游戏时,应使用Debug。

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. 将此代码放在Eclipse中的新项目中。

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

Click on the int = 0; 点击int = 0; line and press CTRL+SHIFT+B you will notice a small dot will appear to the left of the line. 并按CTRL + SHIFT + B,您会注意到该行的左侧会出现一个小点。 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. 从这里可以继续按f6键以“逐步完成”程序。 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.. 这将打开一个变量窗口,该窗口将向您显示程序中逐步执行的部分中的变量。在上面的示例中,按f6键两次或三次后,应该会看到此变量。 变量视图 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. 不仅可以在按f6键时看到变量的变化,还可以双击值列并在运行时更改值以询问是否存在问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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