O'Reilly and Associates

Java in a Nutshell, Third Edition
Examples

[ Back to: Java in a Nutshell, Third Edition ]

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

Note: The code in these example archives may not match the examples in the latest print copy of the book. Please check the posted errata for discrepancies be tween the book and online errata. We apologize for the inconvenience.

If you are looking for the examples from the *second* edition of Java in a Nutshell, click here.

If you are looking for the examples from the *first* edition of Java in a Nutshell, click here.

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.

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) 1999 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.

The filenames identify each example by its chapter number and example number. Example 1-1 is a complete Java program, and is also provided in a file named Factorial.java. As explained in Chapter 1, you can compile and run this program with commands like these:

javac Factorial.java
java Factorial 4

None of the remaining examples have main() methods, so they are not complete programs, and can not be run by themselves. Many of these examples do define Java classes, and, if appropriately renamed, they can be compiled, and used by other Java classes. (Although none of them are particularly useful!). Other examples are simply code fragments, which can be incorporated into other Java code, but which cannot be compiled as is.

Example 1-1

1-1: This program computes the factorial of a number

Example 3-1

3-1:

Example 3-2

3-2:

Example 3-3

3-3:

Example 3-4

3-4:

Example 3-5

3-5:

Example 3-6

3-6:

Example 3-7

3-7:

Example 3-8

3-8:

Example 3-9

3-9:

Example 3-10

3-10:

Example 3-11

3-11:

[ Back to: Java in a Nutshell, Third Edition ]


oreilly.com Home | O'Reilly Bookstores | How to Order | O'Reilly Contacts
International | About O'Reilly | Affiliated Companies | Privacy Policy

© 2001, O'Reilly & Associates, Inc.