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 reading skills of Java source code tracking

2025-03-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you the "Java source code tracking reading skills", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Java source code tracking reading skills" this article.

1. Quick Type Hierarchy takes a quick look at the class inheritance system.

Shortcut key: Ctrl + T

Many people may know that when reading the source code, it is more important to look at the method system, and you can easily and quickly locate the implementation class of the method. Such as:

If you want to see how the getBean () method is implemented at this point, you may be disappointed. The results are as follows:

Enter the interface definition method of BeanFactory, and there is nothing.

At this point, we Ctrl+T directly on getBean:

You can see the subclass of its implementation, click on the subclass to go in. This method also applies to the template method pattern that is very common in the framework, the template method defined in the abstract class, which makes it easy to find the implementation class.

And, of course, a detailed Open Type Hierarchy.

A better Type View will be shown in the left view:

2. Open Call Hierachy opens the call level

Shortcut key: Ctrl+Alt+H

Personally, I think this is the most useful tool to read the source code. By mastering it, you can easily walk between various method calls. However, from the point of view of my friends, many people do not know that he exists.

The result of the Open Call Hierachy view is as follows. The calling relationship is clear and clear, and you can directly locate the calling place.

3. Flexible use of Debug breakpoints

Breakpoint mode, the heart must be very clear about the role of F5, F6, F7, F8, otherwise either lost in the source code, or did not see anything clearly.

Re-talk about what they do:

F5 Step Into, step in. Enter into a method

F6 Step Over, end in one step. Execute the code one by one, many people will only walk one by one at the beginning.

F7 Step Return, jump out and release. When you enter a method, if you find that the method has nothing you want to see, or has seen what you want to see, go straight to F7 and jump out of the method.

F8 Resume, proceed. Go ahead and stop when you encounter the next breakpoint, or you will run all the time without it.

We may often encounter the situation of loadClass when debugging:

In line 40, when you want to enter the ClassPathXmlApplicationContext constructor, F5 unexpectedly enters the class loading:

Students who are familiar with class loading will be very familiar, and those who are not familiar with the class loading mechanism should not panic. This means that the class you are debugging is loaded for the first time. At this time, F7 jumps out of class loading and goes back to line 40.

Pressing F5 at this time will really enter the ClassPathXmlApplicationContext constructor.

When we break point tracking Spring this kind of source code, must have the rhythm, in order to first find the overall vein prevails, do not always F5 into each line to take a closer look, F5 go down, a few days can not finish Spring. To be proficient in F5, F6, F7, F8 in the framework of Spring, it is not far from understanding him.

When Dubug, you should also pay attention to the thread stack of the debug view:

This view allows you to go deeper, you can see at a glance how you got in, what method you are currently in and other information, you can also click on the corresponding number of lines of code to enter the view.

The above is all the content of this article "what are the reading skills of Java source tracking?" Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to 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