Breakpoints and step by step debug in Java?

99封情书 提交于 2020-01-01 18:50:34

问题


Sorry for the strange name of my question. I don't know how to look for this because I don't know how these things are called.

There's a features in Visual Studio at least where you can click on the left of the code and set a starting point which is a big red dot. Then you run the program and you can trace the steps by pressing f8 or f5 (different f's really) and you see the variable values on each step etc. I find it extremely useful because I can see where an error occurs and how the program behaves.

I have no idea what this is called and I want to ask is there such a thing in NetBeans IDE 8.0.2 or jGrasp or any java compiler?

Sorry if anything sounds stupid, I'm kind of a newbie. Thank you all


回答1:


Most IDEs have debugging functionality built in.

In Netbeans, you can easily add/remove a break point by simply clicking the line number on right side of the source editor (you can also do via the editor popup menu)

You start the debugger through F5 (ShiftF5 for debug the current file) or via the debug icon on the toolbar

You can use F8 to step over the command/method call, F7 to step into a method. You can resume running the program using F5 while the debugger is running.

See Debugger and Profiler and Using the Visual Debugger in NetBeans IDE for more details




回答2:


Finding how to do this in your IDE is pretty easy, see the other answers.

What is a bit more difficult is debugging an external (and/or) remote Java program in your IDE. Here it is how to do that with Eclipse: http://www.ibm.com/developerworks/library/os-eclipse-javadebug/. I guess other IDEs are similar. If you test via Maven/Surefire, you have a simple flag to do the same: http://maven.apache.org/surefire/maven-surefire-plugin/examples/debugging.html



来源:https://stackoverflow.com/questions/28497866/breakpoints-and-step-by-step-debug-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!