Welcome to the Computing Concepts with Java Essentials FAQ!

{short description of image}

Question: What are the most important changes in the second edition?

Question: What version of Java does the second edition use?

Answer: The second edition uses Java 2.

Question: Does the second edition work with the Mac? Linux?

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.

Question: Does the second edition work with J++?

Answer: No. Microsoft J++ is not compatible with Java 2.

Question: What happened to the ccj package?

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.

Question: What happened to console input and formatted output?

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.

Question: What should students do in CS2 if they got used to ConsoleReader in CS1?

Answer: See this note for several alternatives. .

Question: Why doesn't Ctrl+Z end of input detection work with JDK 1.3 on Windows?

Answer: I don't know why—this 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);
      }

Question: What happened to the old cover?

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.

Question: Why is class implementation now taught earlier than in the first edition?

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.

Question: I want to teach programming concepts, not graphics. Can I skip the graphics chapters?

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.

Question: Why are you using applets? Aren't applets on their way out?

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.)

Question: Why are you using the Graphics2D and Ellipse2D classes? What is wrong with the drawEllipse method?

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.

Question: Why are you using the Applet class? Shouldn't you use JApplet in Java 2?

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.

Question: Why are you using the show method for objects of the JFrame class? Don't you know it is deprecated and that you are supposed to use setVisible(true)?

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).

Question: Why are you using inner classes for event handling?

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.

Question: I am getting weird errors when compiling even the simplest programs. I tried everything, and it still doesn't work.

Answer: If you use Windows, check out the excellent tutorial from Sun Microsystems. It goes through all the steps in excruciating detail.

Question: I am using javac under Windows, and my program has so many errors that they all flash by and I can only see the last few. I even tried redirection (javac MyProg.java | more or javac MyProg.java > errors.txt), and it doesn't work.

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

Question: How can I make a console program pause before quitting?

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) {}

Question: How can I print my homework?

Answer: Here are directions for Windows 95/NT.

  1. If your program is a graphics program, then run it and take a screen snapshot by hitting Alt+Print Screen. Paste the graphics into a paint program (such as MS Paint) or word processor by typing Ctrl+V, then print it.
  2. If your program is a text program, and the input and output fits on a single screen, you can use the same method for taking a screen snapshot of a DOS shell window.
  3. If your program has no input but lots of output, you can redirect the output to a file (see Productivity Hint 6.1) and then print the output file. But that doesn't work if you also need type input because you won't see the prompts.
  4. If your program has both lots of input and output, I don't know a good solution. You can place all inputs into a file, redirect both input and output, and print both the input and output files. But then the input and output won't appear together.

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.

Question: What support materials are available for the book?

Answer:

Question: How can I get the solutions to the exercises?

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.

Question: I am an instructor and have a password to the solution site. Why do I have to keep coming back to look up each question separately?

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.

Further Information