1.10: Java Library Source
- Page ID
Throughout the book, you have used classes from the Java library including
Random, and others. You may not have realized that these classes are written in Java. In fact, you can take a look at the source code to see how they work.
The Java library contains thousands of files, many of which are thousands of lines of code. That’s more than one person could read and understand fully, so please don’t be intimidated!
Because it’s so large, the library source code is stored in a file named
src.zip. Take a few minutes to locate this file on your machine:
- On Linux, it’s likely under:
(You might need to install the
- On OS X, it’s likely under:
- On Windows, it’s likely under:
When you open (or unzip) the file, you will see folders that correspond to Java packages. For example, open the java folder and then open the
awt folder. You should now see
Rectangle.java, along with the other classes in the
Point.java in your editor and skim through the file. It uses language features we haven’t yet discussed, so you probably won’t understand everything. But you can get a sense of what professional Java software looks like by browsing through the library.
Notice how much of
Point.java is documentation. Each method is thoroughly commented, including
@return, and other Javadoc tags. Javadoc reads these comments and generates documentation in HTML. You can see the results by reading the documentation for the
Point class, which you can find by doing a web search for “Java Point”.
Now take a look at
translate methods. There is more to them than you may have realized, but that doesn’t limit your ability to use these methods in a program.
To summarize the whole chapter, objects encapsulate data and provide methods to access and modify the data directly. Object-oriented programming makes it possible to hide messy details so that you can more easily use and understand code that other people wrote.