10 debugging skills that Java programmers should know and java programmer debugging skills
The test can help identify and solve application defects. In this article, the author will use Eclipse, a common development tool, to debug Java applications. However, the debugging methods described here are basically generic and also applicable to NetBeans IDE. We will focus on the runtime.
Before you start, we recommend you read this article Eclipse shortcuts, which will bring you a lot of convenience. This article uses the Eclipse Juno version (Eclipse 4.2) and provides three suggestions before you start!
1. Conditional breakpoint
If you do not know how to add a breakpoint, click the breakpoint on the left panel (before the row number) to create the breakpoint. On the debugging page, the "breakpoint" view lists all created breakpoints. We can add a Boolean condition to the breakpoint, that is, the breakpoint will be activated and the breakpoint will be executed if the Boolean condition is true. Otherwise, the breakpoint will be skipped.
2. Exception breakpoint
In the breakpoint view, there is a J! Mark button! You can use this button to add a Java exception breakpoint. For example, if we want the program to continue debugging when it encounters a null pointer exception (NullPointerException), we can use this button to add an exception breakpoint!
3. Monitoring point
This is a very good function. When the selected properties access or modify the program, the program stops running and allows debugging. Select a class variable in the Outline View and select to switch the monitoring point from the context menu. The attribute monitoring point will be created at the breakpoint (Breakpoints) view displays all monitoring points in the form of a list.
4. Evaluation/check
Press Ctrl + Shift + D or Ctrl + Shift + I to display the value of the selected variable or expression. We can also add permanent observation points to a variable or Expression. When the program is debugging, these observation points will be displayed in the Expression view.
5. Modify the variable value
You can modify the variable value during debugging. Select a variable and enter the variable view. Enter a Value in the corresponding Value column based on the variable type.
6. Stop execution in the Main function.
In running/debugging settings, the "Main" tab is displayed in the edit configuration dialog box. You can check the "Stop in main" check box. If selected, the program stops running at the first line of the main method when debugging a Java program based on the main method.
7. Environment Variables
The environment variable is not added to system properties. You can easily add it in the edit configuration dialog box.
8. Drop to Frame
This is also my favorite feature. During the debugging, you can jump back to the beginning of the stack framework call and execute the command, and the variable value will return to the beginning. Adjust the depth of the stack according to the archive. The main purpose of this function is to quickly return to the State of all variables when the method starts to be executed. Then you can execute it again, in this way, you can perform debugging multiple times in the area you are concerned about, but some side effects may occur during the execution process. For example, the data inserted into the database cannot be deleted!
9. Distribution Filtering
When we enter the (F5) method, we can also access its external library (such as java. *), we may not need this library, you can add a filter on the Perference tab page to exclude this package.
10. Enter, jump out, and return
I put this at the end. In the debugging process, these are things that must be understood (preferably mastered:
F5 -- Enter: move to the next step. If there is a method call in the current row, the control will jump to the first line of the called method for execution.
F6 -- jump out: Move to the next row. If there is a method call in the current row, it will be directly moved to the next row for execution. Does not enter the called method body.
F7 -- Return: jump out of the current method and continue to execute.
F8 -- move to the next breakpoint for execution.
Q: one-click call to programmer Q & A artifacts, one-to-one service, developer programming required official website: www.wenaaa.com
QQ Group 290551701 has gathered many Internet elites, Technical Directors, architects, and project managers! Open-source technology research, welcome to the industry, Daniel and beginners interested in IT industry personnel!