Applet means 'small application'. This has become commonly used to describe Java applets embedded in web pages. And in that context, applets can be regarded as outdated technology.
Applet
Applet means 'small application'. This term has become commonly used to describe Java applets embedded in web pages - to the extent that the HTML based applet element is for embedding Java applets.
That being said:
- An applet does not need to be embedded in a web page
- An applet does not need to be written in Java
- Many embedded Java applets are not 'small'
Gradually this term is being dragged back to its original meaning. In the more general sense, it might be applied to (for example) operating system settings or configuration applets. Such OS specific applets would typically not be written using Java.
Having covered the general meaning, and recognizing that the common usage of 'applet' is still 'Java applet', the rest of this entry will focus on Java applets.
Java Applet
Looking from the specific Java applet context, it is important to understand that no modern browser is supporting Java plugins any more; and therefore Java applets are not supported any more, too! This means: Java applets can be seen as a product that has reached "end of life"; it should not be used any more when developing new products; applets are only relevant in the sense of "how to migrate away" from them.
Java applets are applications written using the Java programming language that are embedded in web pages. Applets typically provide dynamic functionality that is not supported by plain HTML or a combination of HTML and JavaScript.
Perhaps ironically, the functionality of JavaScript is sometimes invoked from Java applets to achieve things that applets cannot do on their own. Further, the deployJava.js
JavaScript provided by Oracle is designed to launch applets after checking a suitable minimum Java version is installed. While Java can do things that JavaScript cannot - most modern applets would not get very far if JavaScript was disabled in the user's browser!
Many 'beginner books' on Java seem to rush into applet development in early stages in the book. This is a huge mistake. Any text that does so should be considered suspect.
While applets might seem easy to develop, they are actually quite tricky. To deploy an applet reliably to 'all comers' (or at least the vast majority) on the WWW is an order of magnitude more difficult again. For more details See Why CS teachers should stop teaching Java applets, a blog entry by the top ranked provider of answers for the applet tag.
The Java applet API provides methods considered handy to web based applications. These include methods to gain images and audio clips, discover and communicate with other applets, ascertain the code base and document base (where am I?) to allow relative references to resources (images, clips, text files, etc.) that the applet might use.
Applets could be embedded in web pages since Java 1.1. With Java 1.2 came Java Web Start, which could launch both applications and applets as free floating entities (not embedded in a web page). With the release of Java 1.6.0_10, applets could remain embedded in web pages, but they also access the functionality of JWS and services of the JNLP API.
Applet 'Hello World' Example
This example requires the Java Development Kit installed. Visit Java SE Downloads for the latest JDK.
/* <!-- Defines the applet element used by the appletviewer. -->
<applet code='HelloWorld' width='200' height='100'></applet> */
import javax.swing.*;
/** An 'Hello World' Swing based applet.
To compile and launch:
prompt> javac HelloWorld.java
prompt> appletviewer HelloWorld.java */
public class HelloWorld extends JApplet {
public void init() {
// Swing operations need to be performed on the EDT.
// The Runnable/invokeAndWait(..) ensures that happens.
Runnable r = new Runnable() {
public void run() {
// the crux of this simple applet
getContentPane().add( new JLabel("Hello World!") );
}
};
SwingUtilities.invokeAndWait(r);
}
}
See also
Applet API - the J2SE JavaDocs for the applet package. The applet package "Provides the classes necessary to create an applet and the classes an applet uses to communicate with its applet context."
Applet Developer's Guide - The definitive guide for applet developers.
Java Rich Internet Applications Development and Deployment document is a guide for deciding between different forms and ways of deploying an application.
Rich Internet Applications Deployment Trail of the Java tutorials.
Java Rich Internet Applications Deployment Advice. It describes the
deployJava.js
script designed to ensure a suitable minimum version of Java is installed before providing a link to a JWS application or launching an applet.Next Generation in Applet Java Plug-in Technology brings Plug-In 2 abilities to applets: such as providing more control over the applet launch and run-time environment, and allowing embedded applets to gain full access to the services of Java Web Start.
JNLP Support in the Next Generation Java Plug-In Technology (introduced in Java SE 6 update 10) goes into further details of the Plug-In 2 abilities of applets.