Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the 10 debugging skills that Java programmers should know

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is about Java programmers should know what the 10 debugging skills are, editor feel very practical, so share with you to learn, I hope you can learn something after reading this article, say no more, follow the editor to have a look.

The author will use the commonly used development tool Eclipse to debug Java applications. But the debugging methods described here are basically generic and applicable to NetBeans IDE, and we will focus on the runtime.

Before we begin, we recommend that you take a look at Eclipse shortcuts's article, which will bring you a lot of convenience. Using the Eclipse Juno version (Eclipse 4.2) in this article, I'll give you three suggestions before you start!

Do not use System.out.println as a debugging tool

Activate and use all involved component log levels

Use the log analyzer to read the log

1. Conditional breakpoint

If you don't know how to add a breakpoint, just click on the left panel (in front of the line number) and the breakpoint will be created. In the debugging interface, the breakpoints view lists all breakpoints that have been created. We can add a Boolean condition to it, that is, the breakpoint will be activated and will be executed if the Boolean condition is true, otherwise it will be skipped.

two。 Abnormal breakpoint

In the breakpoint view, there is a J! Mark button! We 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 feature, and when the selected property accesses or modifies the program, the program stops execution and allows debugging. Select a class variable in the Outline view and select Toggle Watch points from the context menu. Property Watch points will be created and all monitors will be displayed as a list in the Breakpoints view.

4. Evaluation / inspection

Press Ctrl+Shift+D or Ctrl+Shift+I to display the value of the selected variable or expression. We can also add * observation points to a variable or expression that are displayed in the expression view (Expression view) when the program is debugging.

5. Modify variable value

During debugging, we can modify the value of the variable. First select a variable and then enter the variable view (Variables view) and enter the value in its corresponding Value column according to the variable type.

6. Stop execution in the Main function

In the run / debug settings, the edit configuration dialog box has the "Main" tab, and we can check the "Stop in main" check box. If selected, when debugging a Java program based on the main method, the program stops execution at the line of the main method.

7. Environment variable

Instead of adding environment variables to the system properties, we can easily add them in the edit configuration dialog box.

8.Drop to Frame

This is also one of my favorite features. During debugging, you can jump back to the beginning of the call stack framework, and the variable value goes back to the beginning. According to the depth of the rollback stack, the main purpose of this function is that the state of all variables can be quickly returned to the way the method started, and then you can execute it over and over again, so that you can debug many times where you are concerned, but there will also be some side effects during execution, such as the data inserted into the database cannot be deleted!

9. Distributed filtering

When we enter the (F5) method, we can also access its external library (such as java.*), which we may not need, so we can add a filter to the Perference tab page to exclude the package.

10. Enter, jump out and return

I put this on the * * point, these are the things you must understand (*) during debugging:

F5Mel-enter: move to the next step. If there is a method call on the current line, the control will jump to the * * line of the called method.

F6muri-Pop out: move to the next line. If there is a method call on the current line, it moves directly to the next line for execution. Does not enter the body of the called method.

F7mure-return: jump out of the current method and continue execution.

F8mure-move to the next breakpoint to execute.

These are the 10 debugging skills that Java programmers should know, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report