How to Embed a Java Applet

Embed an Applet

Although HTML 4 specification states that the applet tag is deprecated, it is recommended that you use the applet tag to embed Java applets across browsers on all platforms because it is more consistent than other methods.

Please note that with HTML 5, you will need to use the object tag to embed java applets.

Here is an example of the applet tag:

<applet code="Hello.class" width="100" height="100">
Java applet that says Hello World!
</applet>

For both Internet Explorer and the Mozilla family of browsers, if Java Plug-in is installed (version 1.4+) then the latest installed version of Java Plug-in is used to run the applet.

The param element

The param element passes information to the java applet. Take a look at this example:

<param name="username" value="Spongebob">

and to read the passed information, we use the following in java:

String username = getParameter("username");

You can use param for a variety of reasons, such as customizing the applet’s appearance.

Applet Notinited Error

If you’ve used java applets before, you’re bound to have come across an applet notinited (red X) error. Why does this error occur? This error can occur for a couple of reasons.

Incompatible Java Version

If you still get an applet notinited, it could mean that the browser you use does not support the required Java version. To solve this problem, go to java.com, and download the latest Java version available for your browser or Operating System.

Class Not Found Exception

This exception is thrown when the Java class file (the one called by the applet) is not found. When you are uploading your java class file, make sure to set it in the right path, as well as checking to make sure that is named properly.

Poor Programming

If you tried the first two methods, and your applet still shows applet notinited, then it is most likely due to poor programming. What does this mean exactly? Java applets are executed in a sandbox within the browser, and have many restrictions for security purposes. Java applets cannot read files or open sockets, for example, without the proper permissions. To fix this, the programmer should either remove the offending code or sign the applet.

There could be causes to this problem, but those are the top three that come to mind.