Several people have asked which books are best for learning Java. The answer depends on prior programming experience and personal inclination.
Professor Kaelbling recommends the following two books:
Mike Ross recommends Java In A Nutshell by David Flanagan (online here if you are on an MIT network), but admits that it is only helpful if you are already familiar with object-oriented programming from C++. In addition, the newest edition splits all the information about AWT and Swing (the graphics display classes) into a separate book, Java Foundation Classes In A Nutshell.
Juan Velasquez recommends Thinking In Java by Bruce Eckel, which is also available at Amazon.com and at Quantum Books.
Also, MIT has a subscription to Safari which allows you to look
at many technical books online. It's available through Vera on
the MIT libraries
page.
Free Tools
If you shudder at the thought of developing in Emacs or Vi, there
are several free Java IDEs that you can check out. Netbeans and Borland's JBuilder
Personal will work on Solaris, Linux, or Windows, and Netbeans
also supports Mac OS X. For the purpose of class assignments,
however, Emacs, Vi, Notepad, or some other text editor will be
perfectly adequate.
Debugger
Java comes with a command-line debugger, jdb, which is not very
full-featured. IDEs usually come with integrated graphical debuggers.
If you want to use a debugger, but don't want to use an IDE, try
JSwat.
Beanshell
Even if you are an experienced Java programmer, you may not have heard of Beanshell. Beanshell provides an interactive text-shell environment for evaluating Java expressions and interacting with a running JVM. This is a very useful debugging tool, as it allows you to instatiate and call methods on objects without recompiling (though you do need to restart the shell if you want to change a compiled class).
You should avoid using the 1.3 releases of Beanshell, they have serious bugs in managing for-loop iterations. Use the 1.2 releases instead. The 2.0 releases are brand-new betas and may also be buggy (although they do not have the aforementioned for-loop bug).
To install beanshell,
lib/ext
directory of your JVM, or
~/Library/Java/Extensions
on MacOS X, or
java bsh.Interpreter
" from the command-line, or
java bsh.Console
" to run a GUI version
More documentation is available on the Beanshell website.
Assorted Tips
clone()
method, but you
must be careful before using it. A clone()
usually
creates a shallow copy of an object. So, if you clone()
a Vector, you get two different Vectors with independent internal data
structures (i.e. you can delete elements from one Vector and they will
remain in the other Vector), but the objects the Vectors contain are
not duplicated - they both refer (at least initially) to the same set
of objects.
java.lang.Object
, including clone
,
toString
, equals
, hashCode
, and
finalize
. See this excellent essay
by Mark Roulo for details.