Nine tips for debugging Java programs with Eclipse debug

Source: Internet
Author: User

Nine tips:

    1. Logical Structure
    2. Conditional debug
    3. Exception Breakpoint
    4. Single Step Filtering
    5. Skip to Frame
    6. Inspect
    7. Expressions
    8. Display
    9. Remote Debug

The earliest start with the debugging of Eclipse, only will F5 F6 F7 F8, even F7 are not very engaged to understand how to use, when the capital shallow, touch not need complex debug code, slowly work deep, scene touches more, need all kinds of debug skills to improve location bug efficiency, Before looking for help to troubleshoot problems, see him open all kinds of Windows debug various slip is envy envy hate, slowly long illness into a medical oneself also used to slip eclipse of some of the main debugging skills. Share it with a little bit of finishing.

F5678 these four basic skills will be skipped, but the most basic skills can solve 90% problems, so although not to say, but it must be used very slip, I believe that the four of the Friends of the park is more than I used to slip.

1. Logical Structure

The logical structure is mainly used to show the value of the collection data structure stored in the map, it only shows the logical part of the stored value, and the detailed internal structure of the data structure is shielded, it is more convenient for us to view the values stored in the collection structure such as map, we recommend it.

This button is the display of the logical structure of the button, the following two diagram, is not to show the logical structure, is to display the logical structure, it is obvious that the structure is more readable, you can focus on the debug variables.

2. Conditional Debug

Conditional debug is used in scenarios where a certain condition is required to trigger a breakpoint, such as if only the ID is 12345, then the breakpoint is triggered when the ID equals 12345, and the others are spared.

Right click on the breakpoint to select the breakpoint properties, you can see a configuration box, the right of the text block can fill in the condition code, such as id==12345, because each time to do this judgment, if the number of cycles is very large, or a little bit slow, you can go to the toilet to take a water ah what, or very convenient.

3. Exception Breakpoint

As long as the exception breakpoint is used to debug an exception, it can be configured to trigger a breakpoint when the exception occurs, without the need for debug to find the exception.

Clicking on this red circle will pop up the exception window, listing all of the exception classes in your system, and then selecting the exception that requires a breakpoint to be OK.

4. Single Step Filtering

The single-step filtering scenario is when we use F5 to follow a method's interior, often following some of the methods we decide we don't need to see.

This.gettradedetail (UID, itemstr.substring (0,5))

such as this line of code, want to F5 into the gettradedetail interior, Will first execute the Itemstr.substring method, will first enter the substring method, and this method is the JDK string method, determined that no problem, no need to care, single-step filtering is to skip the methods we want to ignore directly to the inside of the target method of a debug technique.

In Window > PreferencesJava > Debug > Step Filtering Settings filter, you can select the packages and classes that need to be filtered out. Also make sure that you enable single-step filtering in the debug view, such as. This filter function is used when you use single-step debugging.

Is the filter configuration, which is typical of some of the JDK's classes and package configurations. is to open the single-step filter at debug time, otherwise it will not take effect.

5. Skip to Frame

Jumping to a frame is a technique of re-entry, and at debug time, Eclipse can jump directly to any of the frames specified in the call stack and have the JVM rerun here. This allows you to rerun some of your code without having to do it again in order to debug the previous code.

It is important to note that variables that have been modified are not reset, and they retain the values at that time.

How to use: Select a frame in the call stack, click the button "Jump to Frame"

6. Inspect

Inspect is used to view the value of an expression, debug for variable values is very tolerant, but the value of an expression is not easy to see, or this sentence:

This.gettradedetail (UID, itemstr.substring (0,5))

If you want to see the value of the gettradedetail, you can't see the value of the variable (although this is probably assigned to a variable ...). To see this expression value, you need to inspect, by selecting the line expression, then right-clicking->inspect, or a more convenient shortcut key combination: Ctrl+shift+i, the following box showing the result of the expression appears:

7. Expressions

The expressions window is also used to look at the values of variables or expressions, open the Expression window in Windows->show Viewz, and then add the expressions you want to see in it, such as this sentence:

This.gettradedetail (UID, itemstr.substring (0,5))

When you debug, you can see the result of the expression being added, and you can change the value as needed.

8. Display

Display is also used to observe and modify the variable or expression, this should be used more people, in the Windows->show Viewz Open the Display window, you can write the expression in the display window, Then right-click to select Display run view result or ctrl+shift+d shortcut key combination, the expression can be a line of code in the program or you write an assignment statement to change the value of variables and so on.

9. Remote Debug

Remote debug can be used to debug the remote server code, to ensure that your local code and remote deployment of code is consistent, you can debug the server code in this way, this is a great tool for Java Web development, or location server problem is simply a disaster.

Remote Debug requires server-side startup JVM to do some open and port configuration, specific configuration online a lot, search can be. Then, in the local debug configuration, double-click Add a remote Java application, fill in the host and the configured debug port, you can start debugging, such as:

Nine tips for debugging Java programs with Eclipse debug

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.