The real experience of Java source reading

Source: Internet
Author: User
Tags jbpm

Original: http://zwchen.iteye.com/blog/1154193

Just in the forum inadvertently, see the source read the post. Looking back on myself a few years ago, reading the source of the excitement and sense of accomplishment (1), can't help but a kind of excitement.
Source reading, I think the core has three points: technical basis + strong curiosity + patience.

Speaking of the technical basis, I make an analogy, if you have never learned Java, or any programming language such as C + +, a start to eat "Core java", you are very difficult to absorb nutrients, especially "deep Java virtual machine" This kind of books, others feel good, not necessarily suitable for you now.
Although Tomcat's source code is beautiful, I would never suggest you read it from the beginning. I will specifically talk about this, temporarily do not unfold.

Strong thirst for knowledge, I think is the most core driver of reading source. I see the vast majority of programmers, the attitude towards learning is basically these levels (very extreme OH):
1, only focus on the project itself, do not understand Baidu a bit.
2, in addition to doing a good project, will also read and project related technical books, see Wikipedia.
3, in addition to reading and project-related books, but also read the IT industry books, such as learning Java, but also to understand the functional language, such as Lisp.
4, find some open source projects to see, a lot of trial third-party framework, will also write a demo.
5, reading the basic framework, Java specification, debug Server Core.

Most programs are 1th, and the 5th requires not only a strong interest, but also courage: can I read it? In fact, you can read it.

Patience, it's really important. Because you rarely see a guide to reading the source of articles or books, and no one asked or suggested that you read. You often get stuck in the process of reading, and one card owner may be trapped in a maze. At this point, you need to do, may be temporarily interrupted, and then look at it from the periphery: such as the API structure, the framework of the design diagram.

I will talk about how to read Java source code, as well as I have read sentiment.

Java source Initial contact
If you've been developing for a year or so, like using the Debug feature of Eclipse. Well, you now have the technical basis for reading the source code.
I recommend starting with the JDK source code, which integrates directly with Eclipse and does not require any configuration.

You can start with the JDK Toolkit, which is the Java version of data structures and algorithms that we learned, such as the list interface and ArrayList, LinkedList implementations, HashMap and TreeMap, and so on. These data structures also involve sequencing algorithms, double benefit.
Interview, the examiner always like to ask the difference between ArrayList and vector, you spend 10 minutes reading the source code, estimated a lifetime can not forget.

Then the core package, which is string, StringBuffer, and so on.
If you have a certain Java IO base, then read the FileReader class. I suggest that you look at Java in a nutshell, which has the entire Java IO architecture diagram. Java IO class Library, if you do not understand its interfaces and inheritance relationships, reading is always confused.
Java IO Package, I think is the most elegant use of inheritance and interface cases. If you are an architect in the future, you will always be dealing with it, such as the development of core classes related to deployment and configuration in your project.

Read these source code, only need to read some core classes, such as ArrayList similar to the twenty or thirty classes, for each class, it is not necessary to read each method. Some methods like string have gone to the virtual machine layer (native method), such as the Hashcode method.

Of course, if you are interested, you can compare to see JRockit source code, the same set of APIs, two implementations, very interesting.
If you want to drill again, take a look at the set of code for the virtual machine, such as the system ClassLoader principle, which is not in the JDK package, the JDK is based on it. JDK Source Zip package only 10来 m, it is like a 50来 M,sun company has downloaded, but very secretive. I've been so excited about finding and reading it for myself.

Java Web Development Source Code
Before reading Tomcat and other source code, must have a certain accumulation. My practical experience, can also be said to be a better ladder is:
1, wrote some servlet and JSP code. Note, not with what struts, it is hard to touch the essence of the servlet. Good use of struts is only fur.
2, read "Servlet and JSP core programming"
3, saw the Sun company Servlet specification
4. Rfc,debug HTTP packets that have seen the HTTP protocol
If you have the above basis, I also do not recommend you start to read the Tomcat source. I suggest you read the Tomcat source code, read the struts source code, struts source code than webwork to be much simpler. This framework can be read 100%, at least webwork I do not read 100%. I used to read the struts source code, I wrote a web framework.

Of course, before reading the struts frame, it's best to look at its mailreader and so on demo, very very good.
If you've done some struts projects, you'll be better off reading them.
Before reading struts, it is suggested to look at the source code of Mvnforum, it partially realized the function of struts, although this BBS did not dare to compliment.

If you've read struts, then start thinking about Tomcat source reading.
However, I still do not recommend reading it directly, read the series of articles on the Onjava website "How Tomcat Works", it is the most simple version of Tomcat. It tells you how HttpServletRequest is implemented inside the container, how Tomcat accepts requests outside of the socket, how your servlet code is called by the Tomcat Container (callback).
Learn JSP, be sure to study the container will be JSP compiled after the servlet source code.
Why do I always call Tomcat a container, not a server? Let's leave this question to you.

If you must read Tomcat, then attend jetty. At least it is embedded, you can set the breakpoint debug directly inside the ECLISPE. Although Tomcat also has an embedded version.

Java Database Source reading
I suggest that you read the Sun's JDBC specification first.
I think you must have written the JDBC code, then you can start reading the source.
If you understand the JDBC specification (interface), then its implementation, JDBC driver must begin to understand, my advice is to read MySQL JDBC driver, because it is open source, elegant design. When reading MySQL JDBC driver source, it is recommended to look at the inside of MySQL, the official right there is a book, "Mysql internals", I read a part of five years ago. For example, you can know the JDBC driver for MySQL, how to interact with the MySQL server developed by the C + + via the socket packet (connect, query).

With the reading above, you can see how your business code, the JDBC specification, the JDBC driver, and the database work together.
If you know these things, you'll be handy when you learn about persistent frameworks like Hibernate and Ibatis.

Read the JDBC driver, then the next step must read the database. And just have a strong database is developed in Java, Hsqldb. It is an embedded database, such as in the desktop client software, such as mail client.
I wrote a little article about it four years ago and I didn't introduce it.

Java Communication and client software
I highly recommend Instant Messenger software wildfire and Spark. You can interpret wildfire as an MSN server, which spark understands as an MSN client. They are communicated through the XMPP protocol.
I've been customizing spark in a project, and of course it includes some changes to the server. So I've read all of their source code.
I recommend them. is because:
1, XMPP enough lightweight, good understanding
2, Learning socket communication implementation, especially the C/s architecture design
3, modular design. They are module-based and you can understand both the modular architecture and the modular technical support: The ClassLoader scenario for Java virtual machines.
4, Event driven architecture. Although the GUI is event-driven, Spark's design is especially elegant

Let's just say, read their source code, you'll be proud to be a programmer, because both their architectural designs and their codes are beautiful.

Java Enterprise-class applications
Of course, this is the kind of framework such as Hibernate and spring.
Before you read the spring source, be sure to look at the "Java EE design and development" written by Rod Johnson, which is the spring design idea. Note, not the Chinese version, the Chinese version is completely spoiled.
Before reading hibernate source, be sure to read the "Hibernate in Action" written by Gavin King, and read the "Enterprise Application Architecture Model" written by Martin Fowler, which specifically addresses the design of the persistence framework. When you think these two books are thoroughly read, then go to the source code.
Also, before reading the source code, you will find that they use a lot of third-party jar package, twenty or thirty, you'd better put those jar package first understand.

When it comes to enterprise applications, it's bound to involve workflow. I read the source of JBPM, the Internet has introduced the JBPM core of the article (Silver Fox). I feel its kernel is 2000 lines, do not be afraid. I have read the JBPM source blog.
Of course, read the workflow source code, the premise is must have in-depth understanding of its theoretical model, as well as write some demo, or do some projects.

I have described above, I have read them, but also suitable for the average person to read.
I also read some non-Java source code, feel good, also recommend to everyone:
Dojo Source CodeIts architecture is elegantly designed to imitate Java's import and extends. But the actual application of a mess. We developed our own framework based on this, but I am not the main force.

Flex SourceWhen Flex was open source at the end of 08, I used it to do a medium-sized project, which should be said to be the forerunner of technology in China. There were no in-depth books or open source projects in the market. I was purely looking at Flex's help documentation and source code to get the project done. Two or three years later, the system is now thought to be quite elegant.

Okay, here's the first introduction.
The above mentioned Java source code, I have been 4 years ago, or even more morning reading. Technology is changing so fast that, like the rapid development of the Internet, many high-performance, distributed databases such as Hadoop are spawned. As I looked, I found myself behind.
In the past few years, there must have been a lot of excellent framework, we may wish to share.

The real experience of Java source reading

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.