Java Reference
In-Depth Information
Solution
Use the Source, Luke. There are thousands of Java apps, frameworks, and libraries available
in open source.
Discussion
Java source code is everywhere. As mentioned in the Preface , all the code examples from
this topic can be downloaded from the book's catalog page .
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? The standard 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 the whole 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 nonpublic parts of the API, as well as the com-
piler (written in Java) and a large body of code written in 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 from a file or network connection. This is written in C because it
actually calls the read() system call for Unix, Windows, Mac OS, BeOS, or whatever. The
JDK source kit includes the source for all this stuff.
And ever since the early days of Java, a number of websites have been set up to distribute
free software or open source Java, just as with most other modern “evangelized” languages,
such as Perl, Python, Tk/Tcl, and others. (In fact, if you need native code to deal with some
oddball filesystem mechanism in a portable way, beyond the material in Chapter 11 , the
source code for these runtime systems might be a good place to look.)
Although most of this topic is about writing Java code, this recipe is about not writing code,
but about using code written by others. There are hundreds of good frameworks to add to
your Java application—why reinvent the flat tire when you can buy a perfectly round one?
Many of these frameworks have been around for years and have become well rounded by
feedback from users.
What, though, is the difference between a library and a framework? It's sometimes a bit
vague, but in general, a framework is “a program with holes that you fill in,” whereas a lib-
Search WWH ::




Custom Search