Java programmers should know ten debugging technique

By Gladys Stephens,2015-06-06 16:37
20 views 0
Java programmers should know ten debugging technique

    Java programmers should know ten debugging


    Try can help identify and resolve application defects, in this article, the author will use the Eclipse common development tools to debug a Java application.But here is common debugging method, this paper applies to the NetBeans IDE, we will focus on runtime.

    Before you begin, recommend everyone to seeEclipse shortcutsThis article, it will bring you a lot of convenience.In this article are using the Eclipse Juno Eclipse (4.2), before 3 PM advice for everyone!

    1. Don't useSystem.out.printlnAs a debugging tool

    2. All the parts that involve the log level to activate and use

    3. Using the log analyzer to read the log

    1. The conditional breakpoints

    If you don't know how to add breakpoints, simply click on the left panel (line number) in front of the breakpoint is created.In the debug interface, "break" view will list all created a breakpoint.We can give it to add a Boolean condition, that is to say, the breakpoint will be activated and if the Boolean condition is true, will perform the breakpoints, otherwise will be carried out to jump past.

    2. The exception breakpoints

    In the breakpoints view, there is a J!Mark button!We can use this button to add a Java exception breakpoints.For example, we want to meet a null pointer exception (NullPointerException), still can continue to debug, then we can use this button to add an exception breakpoints!

    3. Monitoring points

    This is a very good function, elected property access or modify the program, the program will stop and allow for debugging.Choose a class variable in the Outline view and switch from the context menu select monitoring points, attribute monitoring points will be created, the breakpoint (Breakpoints view will be displayed in the form of all monitoring points in the list.

    4. Evaluate/check

    Press Ctrl + Shift + D or Ctrl + Shift + I to show the selected value of the variable or expression.We can also add a permanent observation points to a variable or Expression, when the program debugging, the observation point in Expression view (Expression view) of the display.

    5. Modify the variable values

    In the process of debugging, we can modify the variable's value.To choose the right one variable and then enter the Variables view (the Variables view), depending on the type of the variable in the corresponding input Value in the Value column.

    6. Suspended in the Main function

    In the run/debug Settings, edit the configuration dialog box with the "Main" TAB, we can select the check box "Stop in the Main".If selected,

    then the debug a Java program based on the main method, the program will be suspended in the first line position is the main method.

    7. The environment variable

    Is not the environment variable is added in the system properties, we can edit the configuration dialog box is very easy to add.

    8.Drop to Frame

    This is also one of my favorite function.During debugging, can back to the beginning of the call stack frame is performed, and a variable's value will also be back to the original.Adjust the depth of the stack according to pulling back, is the main purpose of this function all state variables method can quickly back to thestart of time, then you can back to again and again, so you can focus on you place debugging for many times, but also can produce some side effects in the process of execution, such as the inside of the inserted into the database data cannot be deleted!

    9. Distribution of filter

    When we enter (F5) method, we can also access the external libraries (such as Java. *), we may not need this library, can the Perference TAB page to add a filter to exclude the package.

    10. Enter, jump out and return

    I put the last point, in the process of debugging, these is a must to understand things (master) :

    F5 - enter: move to the next step, if the current row has a method invocation, the control will jump to the called method is the first line of the execution.

    F6 - out: to move to the next line.If there is a method call in the current line, then move directly to the next line.Not into the called method inside the body.

    F7 - returns: jump out from the current method, continue to perform.

    F8, move to the next breakpoint executes.

Report this document

For any questions or suggestions please email