Java 2 Update
Late Updates to Java 2
Applets
The text of the book did not include some new updates on how Java 2 applets work with the latest web browsers. At the time of writing, it was understood that future versions of Microsoft's Internet Explorer and Netscape's Communicator would support Java 2 applets internally. However, since press time, the new direction is that Java 2 applets would be supported in plug-in form only. We feel that this is the correct decision and we support it fully.
What this means
Java 1.1 is currently support by web browsers internally. If you visit a web page that contains a Java 1.1 applet, your browser will run the applet using its own internal Java Virtual Machine (JVM). However, a Java 2 applet currently won't work with the Java 1.1 JVM. So, how do you run a Java 2 applet? You use the Java 2 browser plug-in.
A plug-in is a separate program that plugs into a browser and gives the browser additional abilities. Some example plug-ins are the Shockwave Flash plug-in and the RealPlayerä plug-in. By installing a Java 2 plug-in into your browser, you give it the ability to run Java 2 applets.
Why is this good?
The main problem with having a built-in JVM in the browser is that the browser companies (like Microsoft, Netscape, and even Sun) were usually behind the times in having a current JVM in their browser. And who wants to upgrade their browser just to view some web page? By using a plug-in, it’s easy to simply upgrade or install a plug-in. In some cases, plug-in installation can be automatic.
Installing the Java 2 Plug-In
If you haven't already, visit the Sun Microsystems web page on Java 2 plug-ins.
http://java.sun.com/products/plugin
Download (for free) a copy of the Java 2 plug-in for your computer. Make sure you load the correct version for your computer and operating system. You may also want to download the HTML Converter program (see below).
If you are a Microsoft Windows 95/98/NT user, your version of the Java 2 plug-in comes with the standard Java 2 release. So, if you already have Java 2, then you can skip to the next section.
If you are a Unix user then you'll need to load the separate plug-in package. Remember that Java 2 is also known as Java 1.2. Java 1.1 and Java 1.0 are the "old" java. There is also Java 1.3 (a.k.a. Java 3) out there, too. You will want to get this once it's finalized, but not yet (as of December 1999). Get the latest Java 2, which is currently 1.2.2. Confused? Sorry. We'll make sure to harass the next Java engineer we see on your behalf.
Once you have downloaded the correct version, you will need to follow the instructions on installing it. These instructions should be on the download web page.
Using the Java 2 Plug-In
There are several things you need to do once you have the Java 2 plug-in installed. The first is to enable the plug-in itself, and the second it to enable the Java 2 Console. You may also want to disable the caching of the applets in memory. Normally the caching is a good thing, but when you're developing applets, caching is a bad thing. To accomplish these tasks you need to start the Java Plug-in Control Panel. The procedure for doing this is different depending on the operating system you are using.
Windows 95/98/NT Users
1. Bring up START menu
2. Select the "Programs" menu
3. Select "Java Plug-in Control Panel"
4. Enable Plug-in
5. Enable Java Console
6. Disable "Cache JARs in Memory"
7. You may need to restart any IE processes you have running
Solaris (and maybe Linux) Users
Assuming that Netscape is installed in /opt/NSCPcom:
1. Browse the following URL: /opt/NSCPcom/j2pi/ControlPanel.html
2. OR run the following script: /opt/NSCPcom/j2pi/ControlPanel
3. Enable Plug-in
4. Enable Java Console
5. Disable "Cache JARs in Memory"
6. Restart Netscape
Now you should almost be able to run a Java applet. One last step to go:
Other Changes Needed
There are no changes needed to the Java 2 source code for your applets. However, you will need to change the web page HTML files that contain Java 2 applets. For a very well written web page that documents all of this, please see Sun Microsystems' Java 2 plug-in FAQ page.
Here is a summary of the information from Sun's page:
The Old Way
The old way to reference an applet (and the same way we told you in the book) is like this:
<applet
name="MyApplet"
code="MyApplet"
width="400"
height="500"
align="Top"
>
You're browser does not support Java.
</applet>
This method will still work with Java 1.1 applets in most browsers. It will also work with Java 2 applets, but only when referenced with the Java 2 appletviewer program, or with Sun's "HotJava" browser (which no one actually uses).
The New Way
The new way may look more complicated, but you can just cut and paste most of it. The following is the new HTML that will load a Java 2 applet into the Java 2 plug-in:
<OBJECT
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width=150
height=100
align="baseline"
codebase="http://java.sun.com/products/plugin/1.2.2/jinstall-1_2_2-win.cab#Version=1,2,2,0">
<PARAM NAME="code" VALUE="MyApplet.class">
<PARAM NAME="type"
VALUE="application/x-java-applet;version=1.2.2">
<COMMENT>
<EMBED type="application/x-java-applet;version=1.2.2"
width=150
height=100
align="baseline"
code="MyApplet.class"
pluginspage="http://java.sun.com/products/plugin/1.2/plugin-install.html">
<NOEMBED>
</COMMENT>
No JDK 1.2 support for APPLET!!
</NOEMBED></EMBED>
</OBJECT>
Note that the only part your need to change is the italicized text. Everything else can be copied from document to document. The reason that you need to type in the same information twice is that the method for triggering a plug-in is different for Netscape and Internet Explorer. Read Sun's page if you have more questions.
HTML Converter
Sun Microsystems has written a program to help you convert any HTML pages to use the new Java 2 plug-in.
http://java.sun.com/
If you are just starting out, you probably don't have any HTML pages with applets yet, but if you do, you can download (for free) the HTMLConvert program.
Test
Your Browser
Click on the following link to try and run a Java 2 applet from your browser. If you see text that says "Java 2 plug-in is installed correctly" then you're OK! Note, the first time this runs, it may take a while.
Click here for test Java 2 applet.
That's it! Good programming.