For programmers, to know 10 debugging tips, you know a few

For programmers, to know 10 debugging tips, you know a few

** Introduction:

Debugging can not only find applications where the problem lies, we can also address the shortcomings. For Java programmers, they not only have to learn how to develop a decent program inside Eclipse, but also need to learn how to debug procedures. This article introduces the Java programmer must know 10 debugging tips, guaranteed to make you benefit! **

Debugging can help identify and resolve application defects, in this paper, the authors use the development tools we used Eclipse to debug Java applications. But the basic debugging methods presented here are generic, also applies to the NetBeans IDE, we will focus on the above operation.

Before you begin, we recommend you to see Eclipse shortcuts in this article, it will give you a lot of convenience. As used herein, it is Eclipse Juno version (Eclipse 4.2), before you start to mention three suggestions!

Do not use System.out.println as a debugging tool
to log all the components related to the level of activation and use
use Log Parser to read log

1. conditional breakpoint
if you do not know how to add a breakpoint, simply click on the left panel (the front of the line number) break is created. In the debugging interface, "breakpoint" Breakpoints view will be created for all listed. We can add a Boolean condition to it, that is, the breakpoint will be activated, and if the Boolean condition is true, the breakpoint will be executed, otherwise it will be skipped down the execution.

2. exception breakpoint

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

3. The monitoring point
This is a very nice feature, when property access or modify the program selected, the program will stop execution and allows for debugging. Selecting a class variable in the Outline view and select switching monitoring point from the context menu, watchpoint property will be created, the view will be displayed in all of the monitoring points breakpoint (the Breakpoints) in the form of a list.

4. evaluation / inspection
press Ctrl + Shift + D or Ctrl + Shift + I to display the values of selected variable or expression. We can also add an expression of permanent observation points to a variable or when the program in debugging, these observations point of view will be displayed in the expression (Expression view) in.

5. Modify variable values
during the debugging process, we can modify the values of variables. Then enters a first selected variable Variable View (Variables view), according to the type of input variable values in the Value column corresponding to the inside.

6. Stop the execution Main function inside
run / debug settings, edit the configuration dialog there is "Main" tab of this, we can check the "Stop in main" this box. If you really want to learn java you can be in front of this group is five hundred twenty-seven, the middle four hundred thirteen followed by one hundred forty-four, there are technical Daniel personally guide to help you live and free of course, if selected, when debugging a Java-based program main method, the program stops executing the main method of the first row position.

7. Environment Variables
not add environment variables in the system properties, we can easily add in the Edit Configuration dialog box.

8.Drop to Frame
and this is one of my favorite features. During debugging, you can call again to jump to the beginning of the stack frame of the implementation, and will return to the original value of the variable. According to adjust the stack depth retreated, the main purpose of this feature is that all state variables can quickly look back to the beginning of the method execution time, then you can re-execute over and over again, so you can place multiple debug your attention, but also have some side effects in the implementation process, such as inserting data into a database which can not be deleted!

9. The distribution of the filter
when we enter (F5) method, we can also access external libraries (such as java. *), We may not need this library, you can add a filter Perference tab page to exclude this package .

10. Enter, jump out and return

I put this last point, in the debugging process, which is necessary to understand (the best grasp) of the thing:
F5-- enter: move to the next step, if the current row has a method call, the control will jump to the first line of the calling method.
F6-- jump: move to the next line. If there is a method call in the current row, then move directly to the next line will be executed. Not enter the body inside the called method.
F7-- return: out of the current method, continue down the implementation.
F8-- execution moves to the next breakpoint.

Like this article, remember to authors point followers Oh, daily updated articles about java

Guess you like

Origin blog.51cto.com/14456091/2422740