If you know a little Java™, great. If you know more Java, even better! This book is ideal for anyone who knows some Java and wants to learn more.
I started programming in C in 1980 while working at the University of Toronto, and C served me quite well through the 1980s and into the 1990s. In 1995, as the nascent language Oak was being renamed Java, I had the good fortune to be told about it by my colleague J. Greg Davidson. I sent an email to the address Greg provided, and got this mail back:
From scndprsn.Eng.Sun.COM!jag Wed Mar 29 19:43:54 1995 Date: Wed, 29 Mar 1995 16:47:51 +0800 From: [email protected] (James Gosling) To: [email protected], [email protected] Subject: Re: WebRunner Cc: [email protected] Content-Length: 361 Status: RO X-Lines: 9 > Hi. A friend told me about WebRunner(?), your extensible network > browser. It and Oak(?) its extention language, sounded neat. Can > you please tell me if it's available for play yet, and/or if any > papers on it are available for FTP? Check out http://java.sun.com (oak got renamed to java and webrunner got renamed to hotjava to keep the lawyers happy)
I downloaded HotJava and began to play with it. At first I
wasn’t sure about this newfangled language, which looked like a
mangled C/C++. I wrote test and demo programs, sticking them a few at
a time into a directory that I called javasrc
to
keep it separate from my C source (as often the programs would have
the same name). And as I learned more about Java, I began to see its
advantages for many kinds of work, such as the automatic memory
reclaim and the elimination of pointer calculations. The
javasrc
directory kept growing. I wrote a Java
course for Learning Tree, and the directory kept growing faster,
reaching the point where it needed subdirectories. Even then, it
became increasingly difficult to find things, and it soon became
evident that some kind of documentation was needed.
In a sense, this book is the result of a high-speed collision between
my javasrc
directory and a documentation
framework established for another newcomer language. In
O’Reilly’s Perl Cookbook, Tom
Christiansen and Nathan Torkington worked out a very successful
design, presenting the material in small, focused articles called
“recipes.” The original model for such a book is, of
course, the familiar kitchen cookbook. There is a long history of
using the term “cookbook” to refer to an enumeration of
how-to recipes relating to computers. On the software side, Donald
Knuth applied the “cookbook” analogy to his book
The Art of Computer Programming (Addison
Wesley), first published in 1968. On the hardware side, Don Lancaster
wrote The TTL Cookbook (Sams).
(Transistor-transistor logic, or TTL, was the small-scale building
block of electronic circuits at the time.) Tom and Nathan worked out
a successful variation on this, and I recommend their book for anyone
who wishes to, as they put it, “learn more Perl.” Indeed,
the work you are now reading intends to be a book for the person who
wishes to “learn more Java.”
The code in each recipe is intended to be self-contained; feel free to borrow bits and pieces of any of it for use in your own projects.
I’m going to assume that you know the basics of Java. I
won’t tell you how to println
a string and a
number at the same time, or how to write a class that extends
Applet
and prints your name in the window.
I’ll presume you’ve taken a Java course or studied an
introductory book such as O’Reilly’s Learning
Java or Java in a Nutshell.
However, Chapter 1 covers some techniques that you
might not know very well and that are necessary to understand some of
the later material. Feel free to skip around! Both the printed
version of the book and the (eventual) electronic copy are heavily
cross-referenced.
18.190.156.93