10 Tips for debugging features in Eclipse [go]

Source: Internet
Author: User



Original link: http://www.importnew.com/6164.html



You may have seen some articles like "N Things about debugging". But I think I spend about 1 hours a day on debugging, which is a lot of time. So it is very worthwhile for us to understand some of the features that can be used to help us save a lot of time. So it's worth my while to write an article on this subject.


The first: Do not overdo debugging!


The first piece of debugging to keep in mind is this crazy slogan! But I have to say it again here: Don't overdo the debugging! Try to break up the complex logic into separate small units and write unit test code to ensure that the small unit is running correctly. I often see someone do this: click on a large Web application, fill out several forms, jump to multiple pages, just to confirm the correctness of the results of the last page, and then develop the code in the Debug view.



Before you start Tomcat, you should ask yourself: Is there a way to detect code behavior with unit tests? You can find a lot of tutorials that teach you how to write good code. And here I'm mainly talking about the debugging capabilities of Eclipse , which you might not know, or something that has been forgotten for a long time.


Debug View: Conditional breakpoint


Debugging a view is helpful if you are only interested in a part of the program. Let's say you want to see what happens to the 13th loop in a loop, or you're debugging an abstract parent class to see a specific subclass. You can set conditions in the Debug view, right-click the blue breakpoint symbol next to the code, and select "Breakpoint Properties ..." in the pop-up menu. You can choose to return the truth in your code snippet to stop the program or stop when the value of your code snippet changes.





Variable view: Show logical Structure (show lodical Structure)


If you want to see the values in the map or list in the variables view, the default settings for eclipse may not be that convenient. For example, if you are using HashMap, you must open all the subnodes to see the contents of the HashMap and be disturbed by the details of the HASHMAP implementation. But there is a small button on the variable-"Show Logical Structure". It's very handy, especially if you don't implement the ToString () code of an object. My boss just told me in the last few weeks that Eclipse has this feature. You know, he's the kind of person who uses PowerPoint and Excel every day. What a shame it is for a guy like me who is a programmer! ;-)





Variable view: Change Value ... (Change Value ...)


Suppose you change the input value slightly in a web-based form, then we don't need to restart the debug session, you can directly use the variable view to change the value of the variable function. This can save you time and sometimes can help you simulate some strange behavior.





displaying Views (display view)


Do you know there is a "show view"? You can activate this view through Display, window, Show view. Now your eclipse has a completely empty view. You can use this view to enter and validate new code snippets. The code will be executed in the context of the current debug location, which means you can use all the variables and you can even use content assist. To execute this code, you need to select it and then click on the appropriate item by clicking on the right button pop-up menu, or press Ctrl+u (execute) or press Ctrl+shift+i (check).





Navigation: Drop to Frame


I believe everyone knows "step into" and "step over" and even know "step return". This is the most basic skill for debugging to master. I also want to tell you two other ways. I like them very much. The first one is "Drop to Frame". With this feature, you can go back to the past;-), and you can easily go back to where you used to run Java StackFrame. This is very useful for me because I might have missed a point, and with the Drop to Frame feature, I could easily rerun that piece of code.





Navigation: Step into Selection


The second one is "Step into Selection". This function is very simple, but many people are not used. You just need to press Ctrl+alt, and click on the method you want to go, quick and easy. Compared to "step into", "Step Into Selection" is more convenient. For example, if you want to enter a method with many parameters, you can skip the assignment of all parameters in one step. "Run To Line" is also a good feature. You just need to put your mouse in front of that line and click "Ctrl+r".





Navigation: Using shortcut keys


If you no longer use the mouse, you will become more efficient. At least you should have the following shortcut keys:



f5– "Step into"



f6– "Step over"



f7– "Step Return"



f8– "Resume"



ctrl+shift+b– "Toggle Breakpoint"



ctrl+shift+i– "Inspect"


Breakpoint View: Watchpoints


What changed the variable?! Sometimes creating watchpoint can be a great help. When the value of a field to be monitored changes or is read, the debugger stops. Double-click a field and the Watchpoint is displayed in the breakpoint view, and you can edit its properties. You can also set hit count, which means that the debugger will stop when you enter the hits count already reached. This is also suitable for normal breakpoints.





Clear and easy to read objects


The variable view uses the ToString () method to display the value of an object, so we should write a clear and readable ToString () method. Java.lang.Object the default ToString () method is also recommended for Javadoc:


* Returns a string representation of the object. In general, the* toString method returns a string that* "textually represents" this object. The result should* be a concise but informative representation that is easy for a* person to read.* It is recommended that all subclasses override this method.[...]

You can take a look at the Tostringbuilder in Commons-lang. It can help you write a "good, consistent" toString () method.






If you can't modify the ToString () method, such as using a framework or a foreign API, creating "Detail fomatter" in Eclipse can help you. Right-click an object in the variables view and click "New Detail Formatter ...". Then you can define the code, and then this type of object is displayed in this form.



!--Adsense here-->
Original link: Codecentric translation: Importnew.com-Tangxiaojuan


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.