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

How to read the Java source code

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

Share

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

This article mainly explains "how to read Java source code", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to read Java source code" bar!

1. It is recommended to start with the JDK source code, which is directly integrated with eclipse and does not require any configuration.

You can start with JDK's toolkit, the Java version of "data structures and algorithms" we learned, such as List interface and ArrayList, LinkedList implementation, HashMap and TreeMap, etc. These data structures also involve sorting and other algorithms, killing two birds with one stone.

During the interview, the examiner always asks the difference between ArrayList and Vector. If you spend 10 minutes reading the source code, you will probably never forget it.

Then there are core packages, that is, String, StringBuffer, and so on. If you have a basic knowledge of Java IO, you might as well read classes such as FileReader.

I suggest you take a look at "Java In A Nutshell", which contains the architecture diagram of the whole Java IO. Java IO class library, if you do not understand its interfaces and inheritance relationships, then reading is always confused.

The Java IO package, I think, is a case of elegant inheritance and interface application. If you work as an architect in the future, you will certainly deal with it frequently, such as core class development related to deployment and configuration in the project.

When reading these source codes, you only need to understand some core classes, such as 20 or 30 classes similar to ArrayList, and for each class, you don't have to understand every method. Some methods like String have reached the virtual machine layer (native method), such as the hashCode method.

Of course, if you are interested, you can compare the source code of JRockit, the same set of API, two implementations, very interesting.

If you want to drill again, take a look at the code for virtual machines, such as the principle of System ClassLoader, it is not in the JDK package, JDK is based on it. JDK's source code Zip package is only about 10m. It seems to have been downloaded by MJI Sun, but it is very secret. I was excited to find and read it for myself for a while.

2. Read the source code of Java Web project

Step: table structure → web.xml → mvc → db → spring ioc → log → code

① first understands the table structure of the project database, which is the most easy to forget. Sometimes we only look at how each method works, but do not understand the primary and foreign key relationships between databases. In fact, if you first understand the database table structure, and then look at the implementation of a method will be easier.

② then needs to go through the web.xml to know what interceptors, listeners, filters, and configuration files are used in the project. If it is an interceptor, it is generally responsible for filtering requests and performing AOP; if it is a listener, it may be a timing task and initialize the task; the configuration file is like reading mvc-related, db-related, service-related, and aop-related files after using spring.

③ looks at the interceptor and listener code to see what requests are intercepted and what the class does. Some people write an action because of the lack of this step, and the configuration file is not written wrong, but no matter how to debug, they cannot enter the action until someone tells him that the request has been intercepted.

④ next, look at the configuration file, first of all, it must be related to mvc, such as in springmvc, which requests are static resources, which view policies are used, and which package the controller comments are placed under. Then there are db-related configuration files to see what database is used, what orm framework is used, whether secondary cache is enabled, which product is used as secondary cache, transaction management processing, and where the entity classes that need to be scanned are placed. * is the configuration file related to the ioc function of the core of spring, and you know what the injection of interfaces and specific classes looks like. Of course, there are also some configuration files such as apectj, which are also completed in this step.

⑤ log related files, how the various levels of logging are handled, and where log is used to log.

⑥ knows the overall framework of the entire open source project from the above points, so it is no longer so difficult to read each method.

⑦, of course, if there is a project supporting the development documentation is also to read.

3. Read the source code of Java framework

Of course, there are frameworks like Spring and MyBatis.

Before reading the Spring source code, be sure to read the book "J2EE Design and Development", which is the design idea of Spring. Note that it is not the Chinese version, the Chinese version is completely spoiled.

If you want to read the source code of MyBatis, you must first understand some of its concepts, otherwise you don't understand anything in the clouds and fog. Many people will choose to buy some books to help read, of course, this is desirable. So if you don't want to, you can go to the official website to check its introduction.

Thank you for your reading, the above is the content of "how to read the Java source code", after the study of this article, I believe you have a deeper understanding of how to read the Java source code, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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