Solutions to selected exercises can be found in the electronic document The Thinking in Java Annotated Solution Guide, available for a small fee from www.BruceEckel.com.
- Following the HelloDate.java 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 dont 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.
- Find the code fragments involving ATypeName and turn them into a
program that compiles and runs.
- Turn the DataOnly code fragments into a program that compiles and
- Modify Exercise 3 so that the values of the data in DataOnly are
assigned to and printed in main( ).
- Write a program that includes and calls the storage( ) method
defined as a code fragment in this chapter.
- Turn the StaticFun code fragments into a working program.
Write a program that prints three arguments taken from the command line. To
do this, youll need to index into the command-line array of
- Turn the AllTheColorsOfTheRainbow example into a program that
compiles and runs.
- Find the code for the second version of HelloDate.java, which is the
simple comment documentation example. Execute javadoc on the file and
view the results with your Web browser.
- 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.
- In Chapter 4, locate the Overloading.java 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"> This can be a flashpoint. There are those who say clearly, its 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 youre not passing by reference, youre 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 Im lying to you, but Ill say that Im providing an appropriate abstraction.)