exercises A and B on page 63, the corresponding solutions (right half of page 68) indicate that these classes need to be changed to compile. This isnt what I thought when I did the exercises and was surprised to see corrections during subsequent review of the answers. Being a good sport, I typed these two exercises (three classes) into two *.java files, named
. I then compiled them without a hitch. They dont run, but they do compile. And I understand why they get NullPointerException and ArrayIndexBoundsException respectively. Should the name/purpose of this exercise be changed from
Be the compiler
Be the JVM
and make the point of the exercise be to play JVM and determine how to change each of these files so that they will both compile and run without error? Thank you for reading and your time. Sincerely, -Glen
Hmmmm... Not bad at all. I was thinking personally that I should maybe stick to reviewing and leave the creative stuff to the authors, but maybe that's a cop out. Plus I just had gum surgery, so I'm not feeling very creative. Keep up the good work everyone! Ouch and bye....
My confusion was that the goal of these exercises was to "Be the compiler". The thing is, the compiler does not have a problem with the coding errors in these exercises. I verified this by typing the Java programming language statements from the exercises into files called "BooksTestDrive.java" and "Hobbits.java". I then ran these two new files through the Java compiler, and it turns out that they compile (into *.class files) without any errors. The errors happen later, when you try to actually run the resulting classes (via the Java Virtual Machine). Hence the "Be the JVM" "Be the JDK" suggestions. I like the examples and their presentation, and I do hope I am not confusing matters, but I found it confusing that these programs do compile but do not run.