Java Tip 2: Compile Java with Netscape Navigator under Unix

Compile Java code without the JDK

Now that everyone has had a bit of time to read all of the interesting JavaWorld articles and check out a number of cool Java sites, we are going to dive into an alternative method of compiling and running Java code. All you need is Netscape Navigator 2.0.

Along with the Java virtual machine (JVM) interpreter and runtime system, a Java compiler is built into the Navigator 2.0 browser. So you can now brew some of your own Java without having to get and set up the complete Java Development Kit (JDK), which can be pretty painful on some computers.

This is a blessing for the many Linux folks who cannot run the port of the JDK because they do not have a system supporting ELF. (ELF [Executable and Linking Format] is supplanting the venerable a.out as the executable file format for Linux. It's a mainstay on Solaris and other System V Release 4 Unix clones and derivatives. Check out the Linux ELF HowTo at for more information.)

Netscape Java compilation under Unix

Step 1. Get and install Navigator 2.0 for your platform. Be sure to read the README file for special platform-specific instructions to make Navigator's Java support work properly. For our purposes, the key element of this step is where is placed. On my Linux machine, I put it in /usr/local/netscape/java/classes.

Step 2. Get a copy of the Java Development Kit and extract the java/lib/ file from it. I put it in with in /usr/local/netscape/java/classes for simplicity.

Step 3. Set your CLASSPATH environment variable so that Navigator can find it's "built-in" Java classes along with the Sun Java classes. Be sure to include the "current" directory so you can compile your code as well as use Netscape and Sun .zip file archives. For example:

    setenv CLASSPATH .:/usr/local/netscape/java/classes/

Step 4. Compile your Java code (applet or application) via:

netscape -java [filename].java

(Substitute your Java file's name for "[filename]" above.)

This will translate your Java source code into the Java virtual machine bytecode that is placed into [filename].class.

Step 5. If you compiled a Java application you can run it via:

netscape -java [classname]

(Substitute your application's class name (the one that contains the "main" routine) for "[classname]".)

Step 6. If you compiled a Java applet then you can place it in the appropriate location in your Web server hierarchy and view it by using it in a web page.

You can also view it using the "AppletViewer" by running:

netscape -java sun.applet.AppletViewer [classname]

Unfortunately, using the AppletViewer that way doesn't seem to work on some systems (like my RedHat v2.1 Linux system).

Time-saving script

After you've had enough typing practice, you may want to encapsulate step 3 with steps 4-6 in some shell scripts or batch files.

For a Unix system, try something like putting:

#/bin/csh -f
setenv CLASSPATH .:/usr/local/netscape/java/classes/
netscape -java 

into "javac". Remember to make the script executable and change the "/bin/csh" to the path to where csh lives on your machine. Similarly, we can define the application interpreter and applet viewer by substituting the appropriate netscape line from the steps above.


It seems that using Netscape Navigator to compile Java can be significantly faster than using the Java Development Kit for some people. So if you have the JDK set up, run some of your Java code through both and find out which one is a rich double espresso and which is a foamy decaf latte. Of course, they may both be just regular cappuccinos.

Notice to our Readers
We're now using social media to take your comments and feedback. Learn more about this here.