Owl Sams Teach Yourself Java 1.1 Programming in 24 Hours

Answers to Readers' E-mail Questions

The following answers are in response to e-mail sent by readers. New (and newly updated) questions are presented first.

Question: Would it be better to start with Java 1.1 or is that language obsolete now with Java 2 out?

Answer: Though it's better to start out with Java 2 (currently in version 1.4), about 75 percent of the material in Teach Yourself Java 1.1 Programming in 24 Hours is still relevant to the current version of Java, though some of the methods in the book have been renamed in later versions of the language. One example: size(), a method used in applet windows and other places to figure out the size of the window, was renamed getSize() later.
    If you've bought the Java 1.1 book and you want to get as much use out of it as you can, download JDK 1.1 from Sun (or use the one on the book's CD) and work through the book to learn the basics of the language. When you're done, move on to the current version.

Question: I can't load any of the source files from the CD, and none of the software listed in the Appendix is available. Is the CD incomplete?

Answer: It sounds like your CD is defective -- the CD should contain source files for all of the book's examples and all of the software listed in Appendix E. Check what you have against the full directory listing for the book's CD.
     This book is out of print, so replacements for defective CDs are no longer available. You can download the source files from this site and version 1.1 of the Java Development Kit from Sun Microsystems.

Question: I'm stuck on page 25 of your book, where it states that I should go to the directory on my system containing BigDebt.java and type the javac BigDebt.java command. Where do I type this?

Answer: If you're using Windows 95 or NT, you need to use the MS-DOS prompt when compiling Java 1.1 programs and running them with Appletviewer. Visit this site's online tutorial: Using the Java Development Kit on a Windows System for help with this feature.

Question: How can I use a TARGET with the URL in the Hour 14 Revolve applet?

Answer: In Line 75 of Listing 14.1 (Revolve.java), a URL is loaded with the following statement:

  • browser.showDocument(pageLink[current]);

To load a URL with a TARGET, use a similar method that's outlined in Sun's java.net.URL documentation: showDocument(URL, String). The second argument of this method should be a string containing the name of the target.

Question: On page 318 of Listing 24.2, I am a little confused with how lines 72-81 work. More specifically, I would like to know more about lines 75-76:

  • if (newText.indexOf(".") == -1)
  •     newText += ".";

Answer: The indexOf() method of the String class searches for text inside the string -- such as a "." character in the above example. If the text is found, indexOf() returns an integer indicating the position where it was found. If it is not found, indexOf() returns -1. Lines 75-76 make sure that there isn't a "." character in newText before adding one to the string. You can find out more from Sun's official documentation for the java.lang.String class.

Question: I'm using a Mac. Is there a developer's kit available for Macs that supports Java 1.1?

Answer: Apple has released Mac Runtime for Java 2.1, which incorporates all of Java 1.1's functionality for running Java 1.1 programs, and the Mac Runtime for Java Software Development Kit 2.1. The Software Development Kit supports Java 1.1.8. For readers of this book and my subsequent Java 1.2 tutorials, I've set up a page about Java 1.2 availability on the Macintosh. Visit that page for the most current information I have. For other platforms, Sun lists the platforms that support the JDK on its site.

Question: I can't seem to get the toUpperCase() method to change a string so that it's all capital letters. What am I doing wrong?

Answer: The key to using toUpperCase() is to realize that it doesn't actually change the String object it is called on. Instead, it creates a new string that is all uppercase letters. Consider the following statements:

  • String firstName = "Abner";
  • String changeName = firstName.toUpperCase();
  • System.out.println("First Name: " + firstName);

This example will output the text "First Name: Abner", because firstName contains the original string, while changeName contains it in capitalized form.

Question: I'm having trouble getting the Java compiler to read my .java files, and they don't work with Supercede either. What can I do to fix this?

Answer: Neither the Java Development Kit nor Supercede is likely to function correctly if there are other Java development tools on your system. What I would recommend at this point is to deinstall the JDK, deinstall Supercede, deinstall any other Java development tools you might have, and then reinstall JDK 1.1. The reason for this problem is that each Java development tool puts its own settings into the AUTOEXEC.BAT file, and this can make the other tools confused or inoperable. If you're a purchaser of the Java Starter Kit, you should note that the version of Supercede included with the Starter Kit does not support Java 1.1. The company released a subsequent version that supports 1.1 called Supercede Standard Edition 2.0.2, but that appears to be unavailable since Supercede's developer was purchased by Instantiations Inc.

Question: Is there a list of all the built-in methods that Java supports?

Answer: Sun offers full documentation for all classes in the Java language, including all public methods you can use. Visit the JDK 1.1 documentation page or go directly to the Core API Specification page to browse through the classes in HTML format.

Question: When I save a file with Windows Notepad, it adds a .txt file extension to the filename, as in BigDebt.java.txt. How can I prevent this from happening?

Answer: Put quote marks around the filename when you're saving it, as in "BigDebt.java". This prevents Notepad from adding the .txt file extension to the name. This problem does not occur under all Windows 95 configurations, but on those where it occurs, you won't be able to compile the program unless you rename it to take out the .txt file extension.

Question: One of the figures in Hour 2 shows the Zeus programmer's text editor. Where can I get a copy of this program?

Answer: Zeus for Windows, written by Jussi Jumppanen, is available for download from the software's official Zeus Web site. The software is a text editor designed specifically for use writing programs. It's available for Windows 95, Windows NT, Windows 3.1, and Windows for Workgroups.

Question: In Hour 9, multidimensional arrays are introduced. Is there a way to use the length variable of just one dimension of the array?

Answer: You can use length on each dimension of the array. The first dimension is easy: the name of the array is followed by the keyword length. For each subsequent dimension, use length with a specific element of the array such as element 0. The following statements demonstrate this:

  • int[][][] numbers = new int[12][13][14];
  • System.out.println("Elements in the first dimension: " + numbers.length);
  • System.out.println("Elements in the second dimension: " + numbers[0].length);
  • System.out.println("Elements in the third dimension: " + numbers[0][0].length);

Question: I can't load any of the source files from the CD, and none of the software listed in the Appendix is available. Is the CD incomplete?

Answer: It sounds like your CD is defective -- the CD should contain source files for all of the book's examples and all of the software listed in Appendix E. Check what you have against the full directory listing for the book's CD.
     This book is out of print, so replacements for defective CDs are no longer available. You can download the source files from this site and version 1.1 of the Java Development Kit from Sun Microsystems.

Question: I am trying to write a ping-pong game for two players and I am having some difficulties in applying some of the commands. Can you spare me some time and send some Java programing code for ping-pong with explanation?

Answer: Although I can't tackle that programming project for you, I can point you to some great sites that offer Java games with source code for you to take a look at. First, you should visit Gamelan, Developer.Com's directory of Java resources. Many of its programs include source code. Second, you should check out the site of Karl Hörnell, the best Java game programmer on the planet. He includes source code for every game he hasn't sold to someone else.

Question: When do you expect Java 1.1 standard to be supported by Netscape and Microsoft Web browsers?

Answer: It only recently became available for some Web browsers. Here's the status of 1.1 support in Web browsers:

  • Netscape: Navigator 4.06 supports Java 1.1, according to the Netscape Java support page.
  • Microsoft: Internet Explorer 4.0 supports only a limited portion of Java 1.1, and according to media reports, Microsoft does not intend to offer full Java 1.1 support in its browser.
  • Sun: HotJava 1.0 supports Java 1.1 (and 1.1.1).

Question: I'm having trouble testing applets with Netscape Communicator. I changed and recompiled an applet, but when I went back to the browser and reloaded the page, it ran the old applet and showed me the source code for the new one. What's the problem?

Answer: Browsers sometimes have trouble if you change an applet's class file while the browser is still loaded. They may run the old, cached copy of the class file instead of the new version you have just created. To clear this problem up, exit the browser and reload it. If you still have problems, delete all the temporary files in your browser's cache and then reload it again (or use Appletviewer while you're testing and debugging an applet).

Question: I can't get the ClockTalk program to work under Visual J++. Am I doing something wrong?

Answer: The problem is occuring because Visual J++ 1.1 does not include full support for Java 1.1. ClockTalk is the first program in the book that uses a feature of Java introduced with version 1.1. Because of that, readers will experience a problem if they're using a development tool other than the Java Development Kit, unless that tool supports Java 1.1. Microsoft has written some of its own features that replicate those of Java 1.1, but it's not close enough for you to be able to use Java 1.1 code without error using Visual J++. Visit the Visual J++ home page for more information.

Question: Is the numeric range of the alphabet, from 65 for 'A' to 90 for 'Z', part of the basic Java language? If so, what are 1 through 64 reserved for?

Answer: The numbers 1 through 64 include numerals, punctuation marks, and some unprintable characters such as linefeed, newline, and backspace. A number is associated with each printable character that can be used in a Java program, as well as some unprintable ones. Java uses the Unicode numbering system, which supports more than 60,000 different characters from the different languages of the world. The first 127 characters are from the ASCII character set, which you might have used in another programming language.

Question: Where can I direct a tech question without having to spend money calling Sams Publishing long distance?

Answer: Technical questions regarding the book and topics covered in the book can be sent to the author. Questions about software created by Sun's Java division such as the Java Development Kit can be addressed to the company through the Web site http://java.sun.com. However, you'll probably get faster results by posting a public message to the Usenet discussion newsgroup comp.lang.java.help or one of the other comp.lang.java.* newsgroups.