The importance of reading the source code: such as chefs choose ingredients, play kitchen utensils-How to view Java, Android source code in eclipse

Source: Internet
Author: User
Tags android sdk manager

First of all, many people say, do not look at the JDK source code is not called to learn java. Obviously that's for sure. To make an analogy: the real chef needs to go down from the selection of ingredients, processing, to the final cooking, plate forming, and even to the end of the process to introduce the user to the edible method. In fact, many cooks just do a small part of it, so at most can only be called "stir-fry", not a chef. And many of the top restaurants emphasize material selection, which is to find the raw material that is suitable for a dish at the source, and even in turn, to get a supply chain to supply a particular ingredient and to design a particular cooking technique for the material. This is the resource maximization from the beginning to the use, its embodiment of innovation and internal strength of the place throughout the assembly line! In particular, the chef also needs tools, and if he only knows what the tool can do without knowing its own characteristics, then it must not be able to use the tools for innovative situations and scenarios.

While we are programming, of course, we can look at the corresponding class API description document for use. This is tantamount to other people to provide good material, you go stir fry. It's no problem to fry well, but to stir it up, stir it up, and of course you have to know the meaning behind the ingredients. For example, understand the water content of the ingredients, understand the growing environment of the ingredients and the changes in the properties that occur under different cooking conditions and so on. In this way, your room will not be confined to a small piece.

Back to programming, in the use of a class, if you can learn more about the implementation of its source code, it will be more handy in later use. Even in order to meet their own special needs, you can rewrite the source of a method, or even rewrite its source library. If you can provide a better class than the existing source code base, then the impact of their own innovation is not confined to an application, a set of software, but the benefit of millions of programming enthusiasts!

Said so much, in fact, from the touch of Java programming in this two or three months, has not really seen the source code. today on the Internet to find the next information, try a bit:

First, in Eclipse, do the following:

1. Click "Window", "Preferences" on the left side of the pop-up list select "Java", "Installed JREs";

2. At this point, "installed JREs" to the right of the list pane, listing the JRE environment in the system, select your JRE (usually there is one) first select it, and then click "Edit ..." on the edge, a window will appear (edit JRE);

3. Check this entry for the Rt.jar file: "%java_home_path%\java\jre_1.5.0_06\lib\rt.jar" before the path is to try your own installation path, the main look at the back is "\lib\rt.jar" on it. Point to the left of the "+" number to expand it;

4. Expand, click "source Attachment: (None)" This item, point to the right of the button "source Attachment ...", select "Src.zip" under your JDK directory File (typically at the root of the JDK installation). Then always point "finish" and "OK" to complete the source file and Eclipse link;

Then, at this time in the Java project to press the CRL, and then click the corresponding Java comes with the class name, will open jump to the corresponding source file.

But for Android developers, if you want to use the same method to open Android projects in Android, the JDK Java class source code, it seems to jump out of the interface can not connect to the source (at least I do). The reason should be, in the Java project, eclipse find its source file is of course in the JDK connection source file inside the search. In the Android project, Eclipse will go to the Android SDK directory to find out. So I couldn't find it. This is the time to establish its connection in eclipse, so that in addition to the Android project can find the corresponding Java source files, but also to find the source files of Android. Start the configuration setup link below:

Activity class Source code: Press the CTRL key, left click on it, the reality of the results can not see the code, the message is "Can't find Activity.class file".


1. Click the button below, "Change attached Source ...", which is to jump out of a popup box;

2, because you need to import the entire" Sources "folder under the Android SDK root directory, you need Click on the pop-up box" external Folder ". Then select the "source" folder under the Android SDK installation directory. Finally click "OK". If pop-up "operation  in  progress ..." description, success. complete the configuration;

3. If the "source" folder cannot be found under the Android SDK installation directory, you need to start the Android SDK Manager to download the source code. After booting, tick the source for Android SDK and click "Installe package ..." in the lower right corner to complete the download. (or you can also download in other ways, and then save to the local, in the above steps to import the source folder, select the corresponding download package for import)

4, to this point, whether in Android project or Java project with CTL and click on the way we open the source of the class we want to open, can be opened to jump to the corresponding file.

The last thing we want to do is to study these tools, especially some algorithms (like the most classic sorting algorithms). Open and patiently read the process of its implementation, will certainly benefit a lot!

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.