Examples From Java in a Nutshell, Second Edition

The Java programming examples linked below are from the book Java in a Nutshell, Second Edition, by David Flanagan, published by O'Reilly & Associates.

Although you can view the example source code online, by following the links below, I recommend that you download the complete set of examples so that you can work with them on your computer locally. They are available as a zip file or as a gzipped tar file.

Reporting Bugs

If you find any bugs in these examples, please send e-mail describing the bug to bookquestions@ora.com. If you have found a workaround to the problem, please include it.

Copyright

The examples were written by David Flanagan, and are Copyright (c) 1997 by O'Reilly and Associates.

You may study, use, and modify these examples for any purpose. This means that you can use the examples, or modified versions of the examples in your programs, and you can even sell those programs. You can distribute the source code to these examples, but only for non-commercial purposes, and only as long as the copyright notice is retained. This means that you can make them available on a public Web site, for example, but that you cannot include them on a commercial CD-ROM without the prior permission of O'Reilly and Associates.

Note that these examples are provided AS-IS, with absolutely NO WARRANTY of any kind, either expressed or implied.

Example 1-2

Scribble.java: an applet of intermediate complexity, used as an example in the introductory chapter.

Example 2-3

throwtest.java: an application that demonstrates how to define, throw, and handle exceptions. This application doesn't do anything other than print out some text, but you might want to study it and play around with it to learn more about how exceptions work in Java. See the usage instructions in the source code.

Example 6-1

FirstApplet.java: the simplest possible applet. Displays "Hello World"

Example 6-2

SecondApplet.java: a fancier version of "Hello World"

Example 6-3

Scribble.java: a simple applet with user interaction. It allows the user to click and scribble in the window.

Example 6-4

ColorScribble.java: the scribble applet, with colors specified through applet parameters in an HTML file.

Example 6-5

Soundmap.java: An applet that displays an image, plays a sound, and demonstrates several other applet capabilities.

Example 7-1

Scribble1.java: a simple applet, using the Java 1.0 event model.

Example 7-2

Scribble2.java: the same applet, using the Java 1.1 event model.

Example 7-3

Scribble3.java: the applet using the Java 1.1 event model and inner classes.

Example 7-4

Scribble4.java: the applet using a low-level interface to the Java 1.1 event model.

Example 8-1

ScribbleFrame.java: a relatively long application that demonstrates many of the new AWT features of Java 1.1, and also demonstrates object serialization and data compression.

Example 9-2

IntList.java: a simple datatype that defines custom serialziation and de-serialization behavior for itself.

Example 10-1

MultiLineLabel.java: a custom AWT component and Java Bean that displays a specified string of text, using multiple lines, if the string contains newline characters.

Example 10-2

YesNoDialog.java: a bean that displays a dialog box.

Example 10-3

AnswerEvent.java: an event type used by the bean.

Example 10-4

AnswerListener.java: the event listener interface used by the bean

Example 10-5

YesNoDialogBeanInfo.java: a BeanInfo class for the bean.

Example 10-6

YesNoDialogAlignmentEditor.java: a property editor class for one of the bean's properties.

Example 10-7

YesNoDialogMessageEditor.java: a property editor class for another of the bean's properties.

Example 10-8

YesNoDialogCustomizer.java: a customizer class for the bean.

Example 11-1

ConvertEncoding.java: an application that converts a file from one character encoding to another.

Example 11-3

Portfolio.java: a dummy stock portfolio program that demonstrates internationalization of dates, times and numbers.

Example 11-4

SimpleMenu.java: a convenience class for simple creation of localized menus using ResourceBundles.

Example 11-5

Menus.properties Menus_en_GB.properties Menus_fr.properties: property files that specify default, British, and French resource bundles for simple menu creation.

Example 11-6

LocalizedError.java: a class that displays a localized error message fora given exception object, using the MessageFormat class.

Example 11-7

Errors.properties: a sample property file used by the previous example

Example 12-1

ShowClass.java: a program that uses the Reflection API to show the fields and methods of a class.

Example 12-2

UniversalActionListener.java: an ActionListener implementation that uses reflection to invoke a named method of an object.