Finding More Java Source Code
Problem
You want even more Java code examples to look at.
Solution
Use The Source, Luke.
Discussion
Java source code is everywhere. As mentioned in the Preface, all the code examples from this book can be downloaded from the O’Reilly site (http://java.oreilly.com). What I didn’t tell you, but what you might have realized by extension, is that the source examples from all the O’Reilly Java books are available there too: the Java Examples in a Nutshell book; the Java Swing book; all of them.
Another valuable resource is the source code for the Java API. You
may not have realized it, but the source code for all the public
parts of the Java API are included with each release of the Java
Development Kit. Want to know how
java.util.ArrayList actually works? You have the
source code. Got a problem making a JTable behave?
Sun’s JDK includes the source for all the public classes! Look
for a file called src.zip or src.jar
; some versions unzip this and some do not.
If that’s not enough, you can get the source for all of the
JDK for free over the Internet just by
committing to the Sun Java Community Source License and downloading a
large file. This includes the source for the public and non-public
parts of the API, as well as the compiler (written in Java) and a
large body of code written in “native” code
(
C/C++):
the runtime itself and the interfaces to the native library. For
example, java.io.Reader has a method
called read( )
, which reads bytes of data ...