Java Notes

John B. Smith

Winter, 1996


This set of notes intended for my personal use in learning Java. Others may find them useful, but they should understand that they are informal and assume a specific computing context -- the UNC Computer Science Unix/AFS system.

Java Materials at UNC

The UNC directory where Java materials are located is /afs/cs.unc.edu/project/contrib/moderated/sparc/java/. The javac compiler and other tools are located in the bin directory there. The library of Java include classes is in the directory, /afs/cs.unc.edu/project/contrib/moderated/sparc/java/src/java/

Compiling Java Code

To compile a Java program, you must be logged in to one of the supported architectures. Currently, that means a Solaris machine, i.e., ashe. Once logged in, access javac from the directory listed above.

Normally, you will be located in the your java/classes directory and issue the command path/javac file.java to produce file.class.


Running Java Code

When you write a Java program, you must keep in mind the distinction Java makes between an application and an applet.

An application is a stand-along program that must have a main method/procedure; it is executed by invoking the Java interpreter within the general computing context.

An applet is a module that is run within the context of a browser or other program that has an integral Java interpreter that provides the context for the applet. An applet is, thus, normally invoked as a result of an applet tag included within an html document that is accessed by a Java-capable browser.

Thus, to run Java code, you have several options:

  1. To run an applet, you can use a Netscape 2.x browser running on one of the supported platforms and redirect the Netscape window through X to a Unix workstation. Currently (1/21/96), that means running on one of the Sparc stations, e.g., baldhead. This requires 4 steps, after starting up X:
    1. login to a machine where Netscape 2.x is supported, such as a Sparcstation, e.g., baldhead
    2. setenv DISPLAY host:0, where host is the name of the local workstation
    3. xhost + baldhead
    4. initiate Netscape; valid path is /usr/local/contrib/unmod/bin/netscape-2b6


  2. To run an applet, you can also use a Netscape 2.x browser running on one of the supported platforms and redirect the Netscape window through MacX to a Mac workstation. This requires 4 steps, after starting up X:
    1. start MacX, designating baldhead or another appropriate machine as the host; /usr/local/bin/X11/xterm -ls -title "(host xterm" -sb -display "(display" is a valid remote command
    2. once an xterm window comes up for the host, start Netscape, using a valid path, as listed above


  3. A third way to run an applet is to use the Appletviewer included in the Java Developer's Toolkit. It is the most general way and probably the preferred way during debugging. It is a standalone Java interpreter for applets, as opposed to the standalone Java interpreter for applications described below. It can be run with an html file, thereby opening a separate window in which each applet encountered in the file (within an applet tag) is run. Once the Appletviewer is running, a single pull-down menu provides several useful options, including a reload. Although the documentation states that the Appletviewer can be run without supplying an html file (so that you may subsequently open files from the viewer), I have not been able to get the viewer to work in this mode.
    1. login to a machine where the Java tools may be run; currently, that means a Solaris architecture in our UNIX environment, i.e., ashe.
    2. invoke the Appletviewer and supply it with a URL or filename for an html page which references the applet(s) to be displayed


  4. To run an application, you must invoke the Java interpreter:
    1. java classname
    2. note that classname does not include the class suffix.
    For additional details, see the Sun tutorial entitled The Anatomy of a Java Application.

References

Primary Documents
Sun Java Language: White Paper
Sun HotJava Browser: White Paper

General Sources of Information on Java
Omar Siliceo's WWW Virtual Library The Java Programming Language

Getting Started
Derek Hamner/Maria Winslow Introduction to Java
Sun Java: Programming for the Internet homepage for Java
Sun Hooked on Java pages that accompany the book

Tutorials
From HelloWorld to Tickertape. Start-from-scratch tutorial for applet writing.
Sun Writing and Using HotJava Applets tutorial
Elliotte Rusty Harold's Brewing Java: A Tutorial. Long, textbook-length totorial.

Java Programming
Sun API browser, with indices
Sun HotJava User's Guide

Java Archives
Sun Aplett API Packages
Gamelan Archive of Java applets and information
Mentor Digital Espresso archive; includes weekly summary of traffic in Java newsgroups
Sun Hooked on Java applets. Good examples; many, but not all, include links to source
Yahoo's Computers/Languages/Java list.

Java Discussion
Java usenet


email: jbs@cs.unc.edu
url: http://www.cs.unc.edu/~jbs/