Java Applets
  • A Java applet runs in the context of a browser. The Java Plug-in software in the browser controls the launch and execution of Java applets.
  • The Java Plug-in software creates a worker thread for every Java applet. It launches an applet in an instance of the Java Runtime Environment (JRE) software.
  • Java applets can invoke JavaScript functions present in the web page. JavaScript functions are also allowed to invoke methods of an applet embedded on the same web page. The Java Plug-in software and the JavaScript interpreter orchestrate calls from Java code to JavaScript code and calls from JavaScript code to Java code.
  • The Java Plug-in software is multi-threaded, while the JavaScript interpreter runs on a single thread (in most browsers). Hence, to avoid thread-related issues, especially when multiple applets are running simultaneously, keep the calls between Java code and JavaScript code short, and avoid round trips, if possible.
  • An applet cannot handle requests from JavaScript code in the web page until the applet has been initialized.
  • An applet UI can be designed using Swing GUI.
  • An applet can manipulate its parent web page, interact with JavaScript code in the web page, find other applets running in the same web page, show other documents and pages, etc.
  • Every web page is composed of a series of nested objects. These objects make up the Document Object Model (DOM). A Java applet can traverse and modify objects of its parent web page using the Common DOM API. In order to traverse and manipulate the DOM tree, you must first obtain a reference to the Document object for the web page.
  • A Java applet that is deployed by specifying the draggable parameter can be dragged outside of the browser and dynamically transformed into a Java Web Start application.
  • Java applets, like other Java programs, can use the API defined in the java.net package to communicate across the network. A Java applet can communicate with server applications that run on the same host as the applet.

Deploying an Applet

  1. You can launch an applet by specifying the applet's launch properties directly in the <applet> tag. This old way of deploying applets imposes severe security restrictions on the applet.
  2. Alternatively, you can launch your applet by using Java Network Launch Protocol (JNLP). Applets launched by using JNLP have access to powerful JNLP APIs and extensions.

Applet Security

Applets can be signed using a security certificate to indicate that they come from a trusted source. Signed applets operate outside the security sandbox and have extensive capabilities to access the client. A signed applet will run outside the security sandbox only if the user accepts the applet's security certificate. If the user refuses to accept the certificate, the applet will run within the security sandbox similar to an unsigned applet.

When launched by using JNLP, unsigned applets can also perform the following operations:

  • They can open, read, and save files on the client.
  • They can access the shared system-wide clipboard.
  • They can access printing functions.
  • They can store data on the client, decide how applets should be downloaded and cached, and much more. See JNLP API for more information about developing applets by using the JNLP API.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License