Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions




Thinking in Java
Prev Contents / Index Next


Solutions to selected exercises can be found in the electronic document The Thinking in Java Annotated Solution Guide, available for a small fee from

  1. Following the example in this chapter, create a “hello, world” program that simply prints out that statement. You need only a single method in your class (the “main” one that gets executed when the program starts). Remember to make it static and to include the argument list, even though you don’t use the argument list. Compile the program with javac and run it using java. If you are using a different development environment than the JDK, learn how to compile and run programs in that environment.
  2. Find the code fragments involving ATypeName and turn them into a program that compiles and runs.
  3. Turn the DataOnly code fragments into a program that compiles and runs.
  4. Modify Exercise 3 so that the values of the data in DataOnly are assigned to and printed in main( ).
  5. Write a program that includes and calls the storage( ) method defined as a code fragment in this chapter.
  6. Turn the StaticFun code fragments into a working program. Write a program that prints three arguments taken from the command line. To do this, you’ll need to index into the command-line array of Strings.
  7. Turn the AllTheColorsOfTheRainbow example into a program that compiles and runs.
  8. Find the code for the second version of, which is the simple comment documentation example. Execute javadoc on the file and view the results with your Web browser.
  9. Turn docTest into a file that compiles, then run it through javadoc. Verify the resulting documentation with your Web browser. Add an HTML list of items to the documentation in Exercise 10. Take the program in Exercise 1 and add comment documentation to it. Extract this comment documentation into an HTML file using javadoc and view it with your Web browser.
  10. In Chapter 4, locate the example and add javadoc documentation. Extract this comment documentation into an HTML file using javadoc and view it with your Web browser. href="TIJ304.htm">[10] This can be a flashpoint. There are those who say “clearly, it’s a pointer,” but this presumes an underlying implementation. Also, Java references are much more akin to C++ references than pointers in their syntax. In the first edition of this book, I chose to invent a new term, “handle,” because C++ references and Java references have some important differences. I was coming out of C++ and did not want to confuse the C++ programmers whom I assumed would be the largest audience for Java. In the 2nd edition, I decided that “reference” was the more commonly used term, and that anyone changing from C++ would have a lot more to cope with than the terminology of references, so they might as well jump in with both feet. However, there are people who disagree even with the term “reference.” I read in one book where it was “completely wrong to say that Java supports pass by reference,” because Java object identifiers (according to that author) are actually “object references.” And (he goes on) everything is actually pass by value. So you’re not passing by reference, you’re “passing an object reference by value.” One could argue for the precision of such convoluted explanations, but I think my approach simplifies the understanding of the concept without hurting anything (well, the language lawyers may claim that I’m lying to you, but I’ll say that I’m providing an appropriate abstraction.)

    [11] static methods, which you’ll learn about soon, can be called for the class, without an object.

    [12] With the usual exception of the aforementioned “special” data types boolean, char, byte, short, int, long, float, and double. In general, though, you pass objects, which really means you pass references to objects.

    [13] The Java compiler and documentation from Sun was not included on this book’s CD because it tends to change regularly. By downloading it yourself, you will get the most recent version.

    [14] IBM’s “jikes” compiler is a common alternative, as it is significantly faster than Sun’s javac.

    [15] Originally, I created a tool using Python (see, which uses this information to extract the code files, put them in appropriate subdirectories, and create makefiles. In this edition, all the files are stored in Concurrent Versions System (CVS) and automatically incorporated into this book using a Visual BASIC for Applications (VBA) macro. This new approach seems to work much better in terms of code maintenance, mostly because of CVS.

    [16] To preserve space in this book and seminar presentations, not all of these guidelines could be followed.

    Thinking in Java
    Prev Contents / Index Next

   Reproduced courtesy of Bruce Eckel, MindView, Inc. Design by Interspire