Answer: The second edition uses Java 2.
Answer: As soon as Java 2 implementations are available for the Mac and Linux, the book will work with them. In the meantime, I am supplying a compatibility package that maps the Java 2 features used in the book to JDK1.1.
Answer: No. Microsoft J++ is not compatible with Java 2.
Answer: One of the changes in the new edition is that it no longer uses a separate ccj package. There were good reasons to use a supplementary package with older versions of Java. However, using the advances of the latest Java release, I have found a way to eliminate the use of a supplementary package, while still teaching fundamental concepts, not ephemeral Java minutiae, in the book.
Answer: I use and explain a very simple ConsoleReader class that encapsulates the tedium behind the standard mechanism. In the few cases that formatted output is required, I use NumberFormat.
Answer: See this note for several alternatives. .
Answer: I don't know whythis is a common annoyance with various versions of C++ and Java compilers. The symptom is that some output is lost when the end of file is encountered. Fortunately, it is easy to implement a workaround in the ConsoleReader class. Add the boldface line in the readLine method:
public String readLine() { String inputLine = ""; try { inputLine = reader.readLine(); // workaround for Java 2 SDK 1.3 bug on Windows 9x if (inputLine == null) System.err.println(); } catch(IOException e) { System.out.println(e); System.exit(1); }
Answer: Much to the relief of the sales staff, the old cover has been replaced by a new and tasteful one. The new cover has been certified to be 100% joke-free and compatible with the dignity of the computer science curriculum.
Answer: In the first edition, I first taught students how to use classes, and several chapters later, they learned how to write their own. In this edition, students learn how to read and write very simple classes in chapter 3. This is necessary for students to understand the console class and graphics programming. It also removes a lot of the mystery, "programming by imitation", and the overuse of static methods. More advanced features are covered in chapters 7, 9, and 14.
Yes, you can. The book has been designed so that the graphics chapters can be safely skipped without disrupting the remainder of the course. Of course, there are quite a few exercises that use graphics, and you won't be able to assign them.
Answer: The book uses applets in its first graphics chapter, then switches to graphical applications and frames in its second graphics chapter. There is a simple reason. Applets require far less machinery than applications. In particular, the pesky issue of closing an application window is deferred.
As an aside, from a business standpoint, the perception that applets are on their way out may not be entirely correct. I am aware of a good number of interesting and useful applet deployment projects for intranets. When download speed isn't an issue and low client administration cost is, then applets have a significant advantage. Also note that Java 2 has improved the applet security model which enables users more control over applet access privileges. (However, this book does not teach the security model.)
Superficially, it might seem easier to simply call
g.drawEllipse(x, y, w, h);
instead of
Graphics2D g2 = (Graphics2D)g; Ellipse2D.Double egg = new Ellipse2D.Double(x, y, h, w); g2.draw(egg);
Using an explicit object gives students more exposure to objects. After all, the purpose of the graphics chapter is ultimately not to have students draw pretty pictures with a minimum of code, but to teach them how to program with objects.
Answer: Painting directly on the surface of a JApplet is not recommended. Therefore I use the plain Applet class in chapter 4 and introduce JFrame and JApplet in chapter 10.
Answer: The show method of the Component class is indeed deprecated. However, JFrame inherits the show method of the Window class which is not deprecated. That method makes the window visible and brings it to the front. For that reason, calling show() is superior to calling setVisible(true).
Answer: Using inner classes for all event handlers has one great advantage: consistency. For that reason, most user interface builders use inner classes for all events. Java programs that are programmed by hand tend to use inner classes only for event adapters, which leads to different styles for handling action events, mouse events, and window events. Event handling is hard enough for beginners. Using a consistent style really helps clarify the process.
However, I do not use anonymous inner classes--the syntax is just too mystifying for beginners.
Answer: If you use Windows, check out the excellent tutorial from Sun Microsystems. It goes through all the steps in excruciating detail.
Answer: The javac compiler sends error messages to the standard error stream, not the standard output stream. Unfortunately, the Windows shell does not allow redirection of the standard error stream to a file.
Remedy: Use the errout.exe program to redirect the standard error stream to the standard output stream:
errout javac MyProg.java | more errout javac MyProg.java > errors.txt
This is a simple C program--source code below:
#include <io.h> #include <stdio.h> #include <process.h> int main(int argc, char* argv[]) { dup2(1, 2); // make stderr go to stdout execvp(argv[1], argv + 1); return 0; }
Or, if you prefer a pure Java solution, compile the following Java class:
import java.io.*; public class Errout { public static void main(String[] args) throws IOException { Process p = Runtime.getRuntime().exec(args); BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream())); String line; while ((line = err.readLine()) != null) System.out.println(line); } }
Then execute the following command:
java Errout javac MyProg.java | more java Errout javac MyProg.java > errors.txt
Answer: You would want to do this if your integrated development environment immediately closes a console application when it has completed, giving you no chance to admire the output.
The following method always works. Add these lines to the end of your program:
System.out.println("Hit ENTER to exit."); try { System.in.read(); } catch (Exception e) {}
Answer: Here are directions for Windows 95/NT.
I don't have information for other operating systems, but I will gladly publish them if someone lets me know. Frankly, whenever I teach programming courses, I collect the programs on disk or via email and run them myself--it is a simple matter for students to edit a text or image file before printing it out.
Answer:
Answer: If you are an instructor, please visit the Wiley web page and select "Instructor Resources". You will need to fill out a form and obtain a password to see the solutions. If you are not an instructor, unfortunately you cannot get that material. Clearly, instructors would be upset if students could purchase solutions manuals and simply copy the answers instead of doing the work themselves. Therefore, solutions guides have a restricted distribution. I realize that this may be upsetting if you purchased this book for self-study.
Answer: Several people have requested a ZIP file with all answers.
Imagine the following scenario:
As any publisher knows, this is an all too common scenario. Intellectual property is stolen on the internet with distressing regularity. And it is essentially impossible to get a law enforcement agency in another country to act in what they understandably perceive as a minor violation of the law.
We felt that putting the questions on a password-protected web site was a good compromise. As an instructor who needs to look up a few solutions per week, you will not be greatly inconvenienced. Of course, you can save or print individual answers, as needed.