FAQ

This section will try to answer some of the Frequently Asked Questions submitted to us through e-mail. If your question is not answered here, feel free to mail us: javagently@cs.up.ac.za

Index to FAQ

- Netscape refuses to load my new applet
- Setting the path
- Setting the classpath
- The Nature Applet does not seem to work
- Security on example 12.3
- Security in general
- Download the Java compiler
- Teacher's privileged access / Answers to the problems

Netscape refuses to load my new applet

Netscape has this annoying feature that caches Java class files separately from the other Web documents. This means that once Netscape downloads a class file, it will hang on to it and re-use it, even if the class file has changed in the mean time. Switching off your cache in Netscape does not help.

To force Netscape to load your new and improved applet, you need to exit Netscape completely and restart it. It will then load the correct one.

This means that using Netscape to debug applets becomes a real pain. Rather use the Appletviewer to debug applets and only use Netscape or MSIE for the final version.

Setting the path

Most operating systems today make use of an environment variable called the path for find executables. If this variable is not correctly set, you will find yourself getting error messages like "Bad command or file name" in the command prompt on Windows. In order to correctly set the environment variable in Windows 9x, follow these instructions:


In Autoexec.bat file on C:\
Add your jdk1.x.x\bin directory to the "set path=" command.
This can be done in two ways.
1. Add it to the rest of the command line
ex. set PATH=c:\windows;c:\somebin;c:\jdk1.3\bin
2. Add a new set path, remembering to include your old path
ex. set PATH=%PATH%;c:\jdk1.3\bin

Then reboot your computer for the changes to take effect.

For NT/ME users, the instructions follow the basic layout as specified in the classpath section below

Setting the classpath

The classpath variable is an environment setting. Setting it differs for the various operating systems. To include the Text class in a program, the program must import javagently.*. Here javagently is the name of a directory, and the * means that all java classes in that directory must be imported. The directory to be added to your classpath must be the parent directory of the javagently directory.


Lets say my Text.class file's path looks like this
C:\JG\javagently\Text.class.

Windows XP: From the Start menu, select Settings and click on Control Panel. In the Control Panel double-click on the System icon. If you can't find the System icon, this may mean that you are viewing the Control Panel in its Category View. In this case, click on the Performance and Maintenance icon, and then click the System icon, which appears towards the lower right-hand corner. This should open the System dialog box, with six tabs across the top, namely General, Computer Name, Hardware, Advanced, System Restore, Automatic Updates and Remote. Click on the Advanced tab. Now click on the Environment Variables... button, which you can find at the bottom of the dialog box, to the left of the Error Reporting button. This will open another dialog box containing two lists of environment variables. The first is the list allocated to the user currently logged in, and the second to the system in general. The system environment variables can usually only be modified by an administrator.

If CLASSPATH is not listed in the User variables section, then you need to create a new entry by clicking "New" and then filling in the two entries in the pop-up, fairly obviously the Variable Name is "CLASSPATH" and the Variable value is "C:\JG\;." for our example. If the CLASSPATH is already listed, then you can append the path by clicking on "Edit" and simply tacking the new setting on the end of whatever is already there (remember to add a semicolon first). After making your changes, click on the OK button on both the Environment Variables dialog and the System dialog. You will not need to restart your computer, but you will need to restart any applications which may have read the CLASSPATH settings before your changes (including any Command Prompt windows).

Windows 2000: From the Start menu, select Settings and click on Control Panel. In the Control Panel double-click on the System icon. This should open the System dialog box, with a sequence of five tabs across the top, namely General, Network Identification, Hardware, User Profiles, and Advanced. Click on the Advanced tab. Now click on the Environment Variables... button, which appears roughly in the centre of the dialog box. This will open another dialog box containing two lists of environment variables. The first is the list allocated to the user currently logged in, and the second to the system in general. The system environment variables can usually only be modified by an administrator.

If CLASSPATH is not listed in the User variables section, then you need to create a new entry by clicking "New" and then filling in the two entries in the pop-up, fairly obviously the Variable Name is "CLASSPATH" and the Variable value is "C:\JG\;." for our example. If it is already listed, then you can append the path by clicking on "Edit" and simply tacking the new values on the end of whatever is already there (remember to add a semicolon first). After making your changes, click on the OK button on both the Environment Variables dialog and the System dialog. You will not need to restart your computer, but you will need to restart any applications which may have read the CLASSPATH settings before your changes (including any Command Prompt windows).

Windows ME: Click on Start --> Programs --> Accessories --> System Tools --> System Information. This should bring up a "Microsoft Help and Support" window, with a bunch of information about your system. Click on "Tools" on the menu bar and then on "System Configuration Utility". This will bring up another window. Now click on the "Environment" tab which will give you a list of the environment variables which are currently set on your machine. If CLASSPATH is not listed, then you need to create a new entry by clicking "New" and then filling in the two entries in the pop-up, fairly obviously the Variable Name is "CLASSPATH" and the Variable value is "C:\JG\;." for our example. If the CLASSPATH is already listed, then you can append the path by clicking on "Edit" and simply tacking the new setting on the end of whatever is already there (remember to add a semicolon first).

If you need to update your PATH variable to allow you to run the SDK utilities such as the compiler, then this is done is the same way, just edit the PATH entry instead of the CLASSPATH one. Now just check that, under the GENERAL tab, normal startup is checked and click OK. You will be asked to restart your system and hopefully when it comes back up, your CLASSPATH will have been updated.

Thanks to Joe Wrigley from Nottingham, UK for his posting on the discussion board.

Windows NT: Under the System properties in Control panel, choose Environment. In the second window User variables for ... select CLASSPATH and add the appropriate value (i.e. "C:\JG;." in our example). If it is not present already, insert it yourself, following the procedure detailed above for Windows 2000.

Windows 9x: I append the directory C:\JG to the classpath. In AUTOEXEC.BAT, the classpath setting must now look something like this:

 set CLASSPATH = C:\JG\;.

Note the semicolon followed by a period. This is to include the current directory as well. If you previously changed your classpath setting, you just concatenate it by inserting %CLASSPATH% at the end, to form:

set CLASSPATH=C:\JG\;.;%CLASSPATH%

Unix: If you are using csh or tcsh: add the path to the clause

setenv CLASSPATH ~/JG/:.

If you are using a Bourne shell: add the path to

export CLASSPATH=~/JG/:.

Take note of the case sensitivity and the colon to seperate paths.

The Nature Applet does not seem to work.

You need to type in two measurements. Depending on your system, you should also press return when in the text box in order for the number to be registered. On my system (Netscape), the text box then turns grey. Until then, it does not regard the number as typed in. Try the Till program in Chapter 11 for another example of this Java phenomenon.

In addition, and I notice that this is an omission in the HTML instructions (though the book makes things clear), you must also choose one of the leaf patterns by clicking on the corresponding button.

What then happens is the applet goes looking for a picture of the appropriate tree. Due to problems we had with copyright, we have not stored any trees images on the web, so the correct reaction will be something like:

404 Not Found The requested URL /javagently/chap1/Baobab not found

We are working on getting pictures on and are also planning to expand the birds section.

Security on example 12.3

Applets are allowed to read files that are stored on the Web server's file system . To download a file, one needs to set up a URL connection between the Web browser and the server, after which the file can be read as normal. That means that the init() method of class Competition will look like this:

public void init () { // Sets up the applet interface
// First, read in the letter values 
try { 
     URL url = new URL("http://www.cs.up.ac.za/~louis/letter.data"); 
     // (your url will go above, of course) 
     URLConnection con = url.openConnection(); // open the URL connection 
     InputStream is = con.getInputStream(); // get a 
     in = new DataInputStream(is); 
} catch (Exception e) { 
    System.out.println("Error reading letter.data: "+e); 
}
// Create the hash table 
char ch; int l; 
try { 
    winningScore = Text.readString(in); 
    <etc>

Writing files to the Web server, however, is a much more serious problem. The HTTP protocol used in the transfer of the files does not allow for the uploading of files from the Web browser to the Web server. If you want to build a mechanism to do that, you would have to create a Java server that runs on the Web server. You will then have to set up your own mechanism for transferring the file name and file data from the browser to the server. This not quite a trivial task, since many security issues arise. You don't want anyone to have the ability to write files to your Web server...

Security in General

Information on this topic (i.e. writing files from an applet, etc) can be found here. Thanks to Johnny Lo and Basil Worrall for their work on this document.

Download the Java compiler

The Java compiler or JDK is freely available. The newest version as well as previous versions can be downloaded from http://www.javasoft.com/j2se/1.3/.  From there, follow the instructions. The SDK For Java 2 Version 1.3 is now between 25 and 30 MB, depending on the computer you have. It is worth first finding out if your university or company has a local copy. The documentation is 23MB.

Teacher's privileged access / Answers to the problems

The answers to the end-of-chapter problems are only available to teachers and lecturers who are using Java Gently as a course text. In order to obtain access to the solutions, you register with the publishers. If you go to the Lecturers section of this website, there is a link to their page. They need to verify who you are, then you can go ahead. It should take only a day or two.