Hack 41 Run Java Applets Without Crashes or Problems


To get the most out of surfing the Web, you need the most updated version of Java. That can be harder to do than you think, but this hack will show you how.

Running a Java applet when you visit a web site should be a no-brainer; click on a link and the application should run. Unfortunately, XP users have found out that isn't always the case. You may visit Java sites only to find that you can't play games, log into interactive stock and weather sites, or do any of the other things Java can be used for.

Unfortunately, there's no single fix for all Java woes. There are many potential causes, ranging from display errors, to running an old version of Java, and more. Here, though, are the primary ways you can fix Java on your machine.

4.10.1 Make Sure You Have a Java Virtual Machine (JVM) Installed

In order to run Java applets, you need a Java Virtual Machine (JVM) installed on your system. Microsoft and Sun have, in the past, had competing JVMs. Applets written for one JVM may or may not work with the other JVM.

To make things more confusing, Microsoft and Sun have been locked in a bitter legal battle about Java which rivals the Jarndyce and Jarndyce court case at the center of Dickens novel Bleak House. To fully explain the Microsoft/Sun fight would take about as many pages as Dickens' 1,000-plus-page novel. The upshot is this, however: because of a court ruling, Microsoft will no longer distribute or support its JVM (which it calls Microsoft VM) after January 2004. And the Microsoft VM may or may not be enabled in your version of XP.

So if you're having problems with Java, the first thing to do is see whether you have a JVM installed and whether you're using the Sun version, the Microsoft version, or both versions. To see whether Microsoft VM is enabled, from Internet Explorer choose Tools Internet Options Security. Highlight the Internet Zone, choose Custom Level, then scroll down until you come to the Microsoft VM section, shown in Figure 4-14.

Figure 4-14. Checking to see whether you're using the Microsoft VM

If the Disable Java button is chosen, it means the Microsoft VM is disabled on your system.

To check whether you have the Sun JVM and whether it's enabled, from Internet Explorer choose Tools Internet Options Advanced and scroll down. If you see a Java (Sun) entry with a checkbox next to it, as pictured in Figure 4-15, then the Sun JVM is installed.

If you don't have the Microsoft VM or the Sun JVM installed, the solution is simple: install and enable one of them. Because Microsoft will not be supporting its VM after January 2004, your best bet is to install the Sun JVM from http://www.java.com/en/download/windows_automatic.jsp.

If the Microsoft VM or the Sun JVM show up (as in Figure 4-14 or Figure 4-15, respectively), but they're not enabled, you'll need to enable them. To enable the Microsoft VM, in the screen pictured in Figure 4-14 choose High Safety. That will enable the VM but will take security precautions against rogue Java applets. To enable the Sun JVM, select the checkbox under Java (Sun), as shown in Figure 4-15.

Figure 4-15. Checking to see whether the Sun JVM is installed

4.10.2 Uninstall Older JVM Versions

Your problem may be that you have an older JVM or Microsoft VM installed, and you need to update it. Go to http://java.sun.com and check the version number against the version number displayed in Figure 4-15. If your version number is older, you should install a newer JVM. Additionally, if you're using the Microsoft VM, you may instead want to install the Sun JVM in its place, since Microsoft will discontinue support for its VM.

People have reported problems when installing a newer JVM over an older one, so I suggest first uninstalling the old JVM or Microsoft VM and then installing the new one from http://www.java.com/en/download/windows_automatic.jsp. Unfortunately, uninstalling the Sun JVM or Microsoft VM is not a simple process and requires Registry editing as well as manually deleting files. Here's how to do each. Uninstalling an Old Sun JVM

There's good news and bad news about uninstalling an old Sun JVM. The good news is that it might go off without a hitch and take only a single step. The bad news is that you might not be so lucky, and then it'll be time to head to the Registry.

To uninstall an old Sun JVM, choose Control Panel Add/Remove Programs. Select the Java Runtime Environment entry, click Change/Remove, and follow the uninstallation wizard. The JVM will be?or should be?uninstalled.

Sometimes, however, even after you do that, the Java Runtime Environment entry remains in the Add or Remove Programs screen. Theoretically, this should not cause a problem?because the underlying JVM has been uninstalled?but it's not clear whether in practice it will cause problems. So, you'll be best off to remove the entry in the Add or Remove Programs screen. You'll do it by deleting Registry entries and a folder.

Run the Registry Editor [Hack #68] and go to HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Uninstall. You'll find many keys enclosed in curly brackets, like this: {B7915B05-FC28-11D6-9D24-00010240CE95}. One of these keys is the Java uninstall Registry entry, and you need to delete it. You won't be able to know which entry to delete by the key name, because the keys aren't descriptive and each are strings of long numbers enclosed in curly brackets. To find which to delete, you need to find the one that has a DisplayName with a String value that starts with Java, such as Java 2 SDK, SE v1.4.1_02. To find out which key to delete, search for the word Java by pressing Ctrl-F in the Registry, typing the word Java, and then doing a search for it. You'll be brought to the key that needs to be deleted. Before deleting the key, write down its entire name, because you'll need it for the next step. Then you'll delete it.

Next, go to the uninstall folder for Java and delete that folder. Delete C:\Program Files\InstallShield Installation Information\{<Java 2 clsid key>}, where {<Java 2 clsid key>} is the value of the registry key you deleted. After you do that, when you restart Add or Remove Programs, the Java entry will be gone. Uninstalling the Microsoft VM

Uninstalling the Microsoft VM takes a bit of work as well. From the Run box, enter the command RunDll32 advpack.dll,LaunchINFSection java.inf,UnInstall. You'll get a warning box asking if you want to go through with the uninstallation process. Click Yes to continue, and reboot your PC when prompted.

After you reboot, delete these items:

  • The C:\Windows\java folder

  • The java.pnf file from the C:\Windows\inf folder

  • The jview.exe and wjview.exe files from the C:\Windows\system32 folder

  • The Registry subkey HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Java VM

  • The Registry subkey HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\AdvancedOptions\JAVA_VM

That will completely remove the Microsoft VM. You can now install the Sun JVM from http://www.java.com/en/download/windows_automatic.jsp.

4.10.3 Change Your Display Settings

Java applets won't run unless you have a minimum color setting of 256 colors. If you don't use that minimum setting, you'll crash when you visit a web page with a Java applet. To change your display settings, right-click on the desktop, choose Properties Settings, and in the Color Quality drop-down box choose a display setting of at least 256 colors.

If you use at least 256 colors and you still experience problems, the cause may be a buggy video driver. To help find out if this is the cause of the problem, change your current display settings to a lower resolution and color depth than you're currently using?for example, bring it from 1,024 x 768 to 800 x 600, and the colors from Highest (32bit) to 256 colors. If that solves the problem, you may have a display driver with bugs in it. Go to the manufacturer's web site and download a new driver.