Introduction to Programming Using Java, Third Edition

Source Code

THIS PAGE CONTAINS LINKS to the source code for examples appearing in the free, on-line textbook Introduction to Programming Using Java, which is available at You should be able to compile these files and use them. Note however that some of these examples depend on other classes, such as TextIO.class and MosaicFrame.class. To use examples that depend on other classes, you will need to compile the source code for the required classes and place the compiled classes in the same directory with the main class file. If you are using an integrated development environment such as CodeWarrior or Visual J++, you can simply add any required source code files to your project. See Appendix 2 for more information on Java programming environments and how to use them to compile and run these examples.

Most of the solutions to end-of-chapter exercises are not listed on this page. Each end-of-chapter exercise has its own Web page, which discusses its solution. The source code of a sample solution of each exercise is given in full on the solution page for that exercise. If you want to compile the solution, you should be able to cut-and-paste the solution out of a Web browser window and into a text editing program. (You can't cut-and-paste from the HTML source of the solution page, since it contains extra HTML markup commands that the Java compiler won't understand.)

Part 1: Text-oriented Examples from the Text

Many of the sample programs in the text are based on console-style input/output, where the computer and the user type lines back and forth to each other. Some of these programs use the standard output object, System.out, for output. Most of them use my non-standard class, TextIO for both input and output. The programs are stand-alone applications, not applets, but I have written applets that simulate many of the programs. These "console applets" appear on the Web pages that make up the text. The following list includes links to the source code for each applet, as well as links to the source code of the programs that the applets simulate. All of the console applets depend on classes defined in the files,, and Most of the standalone programs depend on the TextIO class, which is defined in

Part 2: Graphical Examples from the Text

Part 3: End-of-Chapter Applets

This section contains the source code for the applets that are used as decorations at the end of each chapter. In general, you should not expect to be able to understand these applets at the time they occur in the text. Many of them use rather advanced techniques. By the time you finish the course, you should know enough to read the sources for these applets and hopefully learn something from them.

  1., an animated design, shown at the end of Section 1.7. (You can use applet parameters to control various aspects of this applet's behavior. Also note that you can click on the applet and drag the pattern around by hand. See the source code for details.)
  2., and applet that shows multi-colored "Java!"s, from the end of Section 2.5. (This depends on
  3., the sample animation applet from Section 3.7. (This depends on This is also listed above, as one of the graphical examples from the text.
  4., showing a grid of colored squares that get more and more red as a wandering disturbance visits them, from the end of Section 4.7. (Depends on (Another applet that shows an animation based on is, the applet version of the solution to one of the exercises for Chapter 4.)
  5., a subclass of the previous example that makes a symmetric pattern, from the end of Section 5.5. Depends on and
  6., an applet with lines that track the mouse, from Section 6.7. This applet uses Java 1.0 style event handling.
  7., an applet that shows symmetric, kaleidoscope-like animations, from Section 7.8. Depends on
  8., an applet that creates a random maze and solves it, from Section 8.5.
  9., a Cellular Automaton applet, from the end of Section 9.4. This applet depends on the file For more information on cellular automata see
  10., an animation of the solution to the Towers of Hanoi problem for a tower of ten disks, from the end of Section 10.5.
  11., the pentominos applet from the end of Section 11.5. This file defines two classes, LittlePentominosApplet and PentominosBoardCanvas. A pentomino is made up of five connected squares. This applet solves puzzles that involve filling a board with pentominos. If you click on the applet it will start a new puzzle. For more information see where you'll also find the big brother of this little applet. This applet uses the old-fashioned Java 1.0 style event-handling.

Part 4: Required Auxiliary Files

This section lists many of the extra source files that are required by various examples in the previous sections, along with a description of each file. The files listed here are those which are general enough to be useful in other programming projects.

David Eck (, May 2000