CMPT 318 99-1: Assignment #3 Hints

Update: Feb 4
  1. JAR files

    The source is given to you in a .jar file. Your JDK should have included a jar extractor. These are typically invoked as

    jar xvf {file}
    If you don't have a jar extractor, you can download one from http://java.sun.com, or you can usually use a .zip file extracting program since .jar and .zip are quite compatible.

  2. Packages

    We have not covered packages very explicitly but they are in the book and quite simple once you get the idea. The code you were given is placed in the package named cmpt318. In order to have your compiler and runtime environment find the .class files and definitions, you may have to instruct them where to find them.

    The "where to find them" is actually JDK/JRE implementation dependent (except for when they've been placed in .jar files). Most implementations, however, map package hierarchies to directory hierarchies. Thus in order to load the class cmpt318.ResultsModel you would need to have the file cmpt318/ResultsModel.class in your CLASSPATH or search directory. So if you include the current directory (i.e. ".") in your search path then the class for cmpt318.ResultsModel will be found if your current directory is the directory containing the directory cmpt318 (you may need to re-read this sentence repeatedly before it makes sense).

    You should consult your own compiler/JRE if you cannot get compilation or running working properly. You may have to package your .class files into a .jar file first.

  3. Testing Locally

    The ResultsModel.setQuery() has a parameter indicating whether the applet is being served from its normal network location. This should ease testing the applet locally (using appletviewer or reading your class files from disk), since dummy values can be used instead of actually trying to connect to AltaVista (which would slow things down anyway).

    The file local-test.html (included in the source .jar file given to you) may help you in your local testing.

  4. Testing on the Network

    Normal browser security rules for applets are that applets should not be able to access any Internet address other than the one that served the applet. Some browsers (apparent Explorer is one of them) will allow applets loaded from local file systems unlimited host access. So far as I know all versions of Netscape do not allow this relaxation in applet security for applets loaded from file systems (except as noted below).

    To test your code using "live" data there are two potential routes you may take:

    1. Put the applet code in your browser's CLASSPATH (or java directory if your browser incomprehensibly does not support CLASSPATH). Most browsers relax network access restrictions for applets that have been loaded from this "trusted" path.

    2. Put only your ResultsModel.class (and any other associated .class files) in your browser's CLASSPATH (or java directory). You can then point your browser to "http://www.cs.sfu.ca/CC/318/walenste/assign/a3/test/query.html". This page serves you a compiled version of the exact same applet code as was given to you, except its .jar file is missing the .class for ResultsModel. Most browsers will then load the definitions for ResultsModel from your local disk. You will probably not be able to use a simple applet viewer in this case since they usually do not deal with the password protection required (you get security violations).

    It is possible that both of these methods fail for you, however all installations I've checked have worked using at least one of these methods. Note that you do not need to test your solution with live data since you can quite easily simulate network latencies by generating fake data with random delays, however doing final testing with network data is frequently entertaining.