Course Links

Exercises

Resources

External

Developing Java Applications on Unix (Console or GUI)

  1. Compile the application with the javac compiler.
    javac myApplic.java
    
  2. If your program consists of multiple files, you can list them all on the compiler command line, or just put them in one directory and use a wildcard.
    javac myFile1.java myFile2.java
    javac *.java
    
  3. Once the program has been compiled, you run it with the java interpreter
    java myApplic
    

Java Applets on Unix

Log into a Linux machine in the computer lab, using your 112 account. You may have to reboot the machine first if it is running Windows.

  1. Go to the public_html directory (cd ~/public_html).
  2. Create and go into a directory where you will be doing the current java work (e.g. cd lab1).
  3. Use emacs to create the HTML file and the java file. E.g.
    emacs lab1.html
    emacs myApplet.java
    
    If you already have an old HTML file that is close to what you want, you can make a copy of it using cp and then modify the copy as required.
  4. Compile with the JDK compiler javac, as for an application.
    javac myApplet.java
    
    The resulting file will be a class file, e.g. myApplet.class.
  5. Make sure the permissions on the html and class files are OK (i.e. everybody can read these files). Use
    ls -l *.html *.class
    
    to see these permissions. If they are not OK, change them with chmod. E.g.
    chmod 644 myApplet.class
    
  6. To view the applet on a Linux desktop, use the appletviewer command:
    appletviewer lab1.html
    
    Alternately, you can launch a web browser and open the HTML page you have created, e.g., http://cs.smith.edu/~112a-xx/Lab1/lab1.html. (See the note below if you do this.)
  7. If you get an error, look into the Java console for more details.
  8. To make corrections, close the applet viewer and go back to the terminal window. Edit your java file, recompile it, and redisplay it.

    CAREFUL: if you are using a web browser to display the applet, and you simply reload the page, the applet may not be reloaded and you will see the old version of your applet (before corrections). You will probably have to close the browser and launch it again. To simplify this process, you can set it to always go to the last visited page, from the Preferences menu.

Javadoc on Unix

  1. The javadoc command creates documentation information for Java classes in a standard format. It should be called with the same settings as javac with the addition of -d doc to put the documentation into a subdirectory.
    javadoc -d doc myClass.java
    
  2. You can view the documentation pages thus created using a web browser. If myClass.java file is in ~/public_html/labX/, then the documentation pages will be at http://www.cs.smith.edu/~112a-xx/labX/doc.
  3. The initial file permission settings may not allow the javadoc pages to be viewed. I have created a script that should fix this problem, called fixPermissions.
  4. Use this command in the same directory where you executed the javadoc command.

J++ on Windows

  1. Go to Start/Microsoft Visual J++/Microsoft Developer's Studio
  2. To write your code, open a new file by clicking on the text file button.
  3. Save the file with the .java extension.
  4. Go to Build/Compile filename. J++ should build a class file.
  5. A window will appear giving you the option to create a new workspace, click yes.
  6. Open another text file and wright the html file corresponding to your class file.
  7. Save it with the html extension.
  8. Go to Build/Execute filename. A window should appear displaying your applet.