Need help with TIJ4-code?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

667 Stars 387 Forks Other 10 Commits 3 Opened issues


Example code for the book "Thinking in Java, 4th Edition"

Services available


Need anything else?

Contributors list

# 49,020
4 commits

Thinking in Java, 4th Edition: Downloading, Installing and Testing the Code

Note that this book covers Java 5/6. The recent book On Java 8 covers Java 8.

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

  1. Download the code by pressing the green button you see towards the top if this page. After pressing the button, select "Download Zip."

  2. Create a directory in which to install the code. For these instructions, we'll refer to this directory as

  3. Using Winzip or some other zip utility, extract the zip file into the

    directory. When you're done, you should see several levels of directories, and in the
    directory, you'll see, among other things, subdirectories corresponding to the chapters in the book.
  4. Install the Java JDK SE5 or later from the download site at Sun. You'll also eventually want the documentation, which is available further down on that page. You may also choose to install Java SE6; the code will work with that as well. Note that the most reliable approach is to install to the default directories.

  5. Add the

    directory of your JDK to your path.
  6. Set the CLASSPATH in your computer's environment. For Windows machines, right-click on the "My Computer" icon and select "Properties." Then select the "Advanced" tab and click the "Environment Variables" button at the bottom. Under "System Variables," look to see if there's already a "CLASSPATH" variable. If there is, double click and add

    to the end of the current entry. If there is no "CLASSPATH" variable, click the "New" button and enter
    In the "Variable name" box, and
    In the "Variable value" box, then click "OK". To verify that your classpath has been set, start a command prompt (see below), then enter
    and look for the
    information in the output.
  7. Install the

    build tool by following the instructions you will find in the Ant download. Note:
    is not required in order to compile the examples in the book. It is used to automate the process, but you can also compile each example individually (once you have the CLASSPATH set, as described above) using the
    command-line compiler that was installed when you completed the previous step (note that you may have to set the Windows PATH to point to
    ). To compile a file called
    , you type
  8. Start a command prompt in the

    directory. To do this in Windows, press the "Start" button, then select "Run" and type "cmd" and press "OK." then type
    cd C:\TIJ4\code
    into the resulting command window.
  9. At this point you should be able to start a command prompt in

    and type
    ant build
    , and the build should successfully compile all the chapters up to the
    chapter, where it will fail with an error message about a missing library. If you only need to work with chapters before
    for now, this will suffice for awhile.
  10. You can also move into individual chapters and type

    (to compile and execute the code in that chapter) or
    ant build
    (to compile the code only).
  11. To build the entire code base, you'll need to install the additional libraries. These include:

    • XOM
    • Javassist
    • The
      library, which comes with the standard Java installation, but which you must explicitly place in your classpath (described below).
    • The Eclipse SWT library. Click on the most recent build number, then scroll down to "SWT Binary and Source" and select the file corresponding to your platform. Further details about finding the jar file are in the book under the heading "Installing SWT."

    In general, you can install the above Jar files by placing them in the

    directory that is part of the "Java Runtime" that will be set up when you install the Java SE5 or Java SE6 development kit. You may have to hunt around for the JRE, but it can often be found under your "Program Files" directory, under "Java."
  12. Alternatively, you can explicitly install each of the Jar files. To do this, you must add each one to your CLASSPATH, following the directions shown earlier on this page. However, you must also include the name of the Jar file in the CLASSPATH entry. For example, if you put the

    file in a directory called
    , then the associated CLASSPATH entry would be
  13. This code is designed to work outside of IDEs. Because packages are not introduced until later chapters, and some of the fancier IDEs like Eclipse require all code to be in packages, if you want to use the code inside those IDEs you will have to make some adjustments (however, see the
    program in the download package for some help). Different IDEs have different requirements and it may be more trouble than it's worth while you're getting started; instead, you may want to begin with a more basic editor like JEdit.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.