10 Tips for debugging Java programs with Eclipse (2) __java

Source: Internet
Author: User

-Navigation: Step Into Selection

The second one is "Step into Selection". It's also very simple, but a lot of people use one. To use it, you just press Ctrl+alt and click the name of the method you want to run to. Very convenient, very fast. Compared to the "step into" this is very convenient, think you like to trace into a function with a lot of parameters, if you have to enter into the ' step ', exit each parameter calculation process to enter the function you really want to go. "Run To Line" is also a great feature. Just put the cursor in front of which line you want to run, and then press "Ctrl+r" on it.

-Navigator: Using the keyboard

If you avoid using the mouse, you will be able to operate more quickly. You should at least have the following shortcuts:

f5– "one Step Into"

f6– "Step and Skip"

f7– "Step and Return"

f8– "Continue execution"

ctrl+shift+b– "Add Breakpoint"

ctrl+shift+i– "Check"

-Breakpoint View: watchpoints

What happens if we change this variable?! Sometimes creating a watchpoint is useful for debugging. The debugger stops, regardless of whether the observed field is modified or read-You can configure the decision yourself. You just double-click a field, and then you can see the watchpoint in the breakpoint view, and you can edit its properties. You can even have an access number, which means the debugger stops when the number of times a variable is accessed reaches that amount. This is true for common breakpoints as well.

-Friendly readable objects

A variable view is a value that uses the object's ToString method to actually correspond. For this reason, it can be very useful for debugging if you provide a friendly ToString method implementation. The default ToString implementation for Java.lang.Object in Javadoc is also recommended:

Returns a String representing the object. Usually the <code>toString</code> method returns such a string, "literally" that object. The return result must be a concise but rich message that can represent the object, and is friendly to read. We recommend that all subclasses override this method.

You can refer to the Tostringbuilder in Commons-lang. It provides functionality to write (referencing from Javadoc) a "good and coherent" tostring method.

The default ToString

The default Tostringbuilder example

Tostringbuilder Example – Multiple lines of text style

If you can't modify the ToString implementation, such as if you are using a framework or an external API, you can have another option to create a "Detail Formatter" in Eclipse. You need to right-click an object in the variable view and click on "New Detail Formatter ...". You can then enter some code to show the object.

Original link: http://www.oschina.net/translate/again-10-tips-on-java-debugging-with-eclipse

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.