Java 如何在 Eclipse 中逐步执行程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4279719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 15:19:29  来源:igfitidea点击:

How do you step through a program in Eclipse?

javaeclipsevisual-studio

提问by doug

I want to follow a Java program so that I can understand how everything works together. I could do it with Visual Studio so I am hoping that Eclipse may also have a feature to step through that I have not been able to find.

我想关注一个 Java 程序,这样我就可以了解一切是如何协同工作的。我可以用 Visual Studio 做到这一点,所以我希望 Eclipse 也可以有一个我无法找到的功能来逐步完成。

回答by Erkan Haspulat

Simply put, you can run your code in Debug Mode by pressing only F11or clicking that little bug on the top of the screen. Use F5to trace into, F6to step over, CTRL-SHIFT-Bto set/remove breakpoints.

简而言之,您可以通过仅按F11或单击屏幕顶部的那个小错误来在调试模式下运行您的代码。使用F5追踪到,F6步过,CTRL-SHIFT-B到设置/删除断点。

回答by Bozho

  1. Put a breakpoint at a given line (double click before the line, or right-click > toggle breakpoint)

  2. Run the program in debug mode. That is - Debug As > Java program

  3. Whenever the breakpoint is reached, the Debug perspective opens, and you can step through.

  1. 在给定的行上放置一个断点(在该行前双击,或右键单击 > 切换断点)

  2. 在调试模式下运行程序。即 - 调试为 > Java 程序

  3. 每当到达断点时,Debug 透视图就会打开,您可以单步执行。

回答by salexander

First you must set a break point in your code. The easiest way to do this is to open up the source file where you want to stop your program, find the line of code where you want to set your break point, and right-click the left-hand margin and select 'Toggle Breakpoint.' Once you've done this, launch your program within Eclipse using the Debug mode. To do this, go to Run>Debug Configurations and set up the configuration to run your program. Alternatively, you can open up the source file that is the entry point to your program (it should include your 'public static void main(String args[])' method), and right-click within the editor and go to Debug As>Java Application. Once the program launches and the code in which your break point is reached, Eclipse will open up the debug perspective. This will show where you are within your program and any variables that you have set. You can step through your program using the buttons in the 'Debug View'. You can also use the menu items within the Run menu to step through the program.

首先,您必须在代码中设置断点。最简单的方法是打开要停止程序的源文件,找到要设置断点的代码行,然后右键单击左边距并选择“切换断点”。 ' 完成此操作后,使用 Debug 模式在 Eclipse 中启动您的程序。为此,请转到 Run>Debug Configurations 并设置配置以运行您的程序。或者,您可以打开作为程序入口点的源文件(它应该包含您的“public static void main(String args[])”方法),然后在编辑器中右键单击并转到 Debug As> Java 应用程序。一旦程序启动并到达断点所在的代码,Eclipse 将打开调试透视图。这将显示您在程序中的位置以及您设置的任何变量。您可以使用“调试视图”中的按钮逐步执行您的程序。您还可以使用“运行”菜单中的菜单项来逐步执行程序。

回答by Sankar Ganesh

Refer step1, step2, step3,step4 images respectively.

分别参考step1、step2、step3、step4图片。

alt text

替代文字

alt text

替代文字

alt text

替代文字

alt text

替代文字