Java applet

from Wikipedia, the free encyclopedia

A Java applet is a computer program created using Java technology and typically executed in a web browser . Applets were introduced to allow programs to run in web pages that work in the web browser (on the client side) and can interact directly with the user without having to send data to the server . Java applets were one of the reasons for the success and rapid spread of Java in the late 1990s .

In addition to applets, there are also servlets ; these are also Java programs, but they are executed on the server .

Applet-related classes of the Java standard library have been marked as deprecated since version 9, which generates a warning at compile time. As of version 11, Oracle has completely removed support for applets.

Java applets in the web browser

Java applets are usually called from HTML pages . In order to be able to run them, the respective web browser must have a corresponding Java VM . This VM, the runtime environment for the Java applet, can either be part of the corresponding browser or be installed later in the form of a Java plug-in (e.g. JRE from Oracle). Another possibility is that the browser - as in the case of historical versions of Opera  - connects directly to the VM, i.e. without going through a plug-in.

Examples of web browsers with integrated Java VM

The functionality of these VMs only corresponds to JDK version 1.1, they are out of date from today's perspective. A current VM can be installed later.

  • Internet Explorer 3, 4, 5 and 5.5 (Java-1.1.4 without RMI / JNI). Microsoft has stopped the further development and distribution of the MSJVM.
  • Netscape Navigator 3.x and 4.x (Java-1.1.5)

Examples of web browsers without an integrated Java VM

To be able to use applets with these browsers, a VM must be installed later.

Applet programming

The integration of the applet in the HTML code of web pages is done by 2015 with the object- element which is opposed to the embedis preferable element. The previously used appletelement is deprecated with HTML4 and obsolete with HTML5 . All Java applets are derived from the Java class java.applet.Applet . You have the following methods , among others , but not a method required main()for Java applications .

  • init() - is called exactly once when the applet is first loaded into the browser.
  • start() - is called every time the applet becomes visible.
  • paint(…) - Drawing method for the display functions of the applet
  • stop()- is called every time the applet is obscured, e.g. B. because the browser window is covered by another window.
  • destroy() - is called when the applet is unloaded from main memory.

The two techniques Swing or AWT can be used to program the user interface . However, there is the limitation that the window embedded in the HTML interface cannot be closed programmatically, but additional windows can be opened.


Applets are executed on the user's computer and therefore - like any locally executable program - represent a security risk (Java Drive-By Exploit). However, since the applets run in an isolated runtime environment ( sandbox ), this risk is easily manageable. A security risk from “malicious” applets only exists if the sandbox is faulty.

Due to numerous security gaps, Java applets without a certificate are blocked by the newer Java versions. Mozilla Firefox completely stopped Java support with version 52.

Areas of application, advantages and disadvantages

The applet technology offers the programmer the full range of functions from the J2SE API , taking into account the security rules, and is very suitable for applications in well-maintained company networks where all users have the same Java version. In cooperation z. Complex applications can be created, for example with servlets or application servers , which in this way dispense with the installation of local software and can run with different browsers and operating systems without great effort.

A disadvantage for use on the Internet and on slow network connections is the size of the JRE with 12.5 MB (as of JRE 6.0). Another disadvantage is the comparatively long initialization time for the JVM if it has not yet been loaded and the time it takes to download and initialize the applet. However, with the introduction of the so-called Java kernel in Java SE 6 Update 10, the loading time of the JVM can be significantly reduced.

It should also be noted that the content of Java applets cannot be recorded by search engines .

Hybrid applet

By adding a main method to a Java applet , it can also be started as a normal Java application by double-clicking on the corresponding jar file . On the one hand, this is useful for test purposes, since the applet does not have to be integrated into a web browser , and on the other hand, a Java application is not executed in a protected area , but is generally given full access to the system (apart from local security restrictions). The latter, however, can be a disadvantage, as a malicious applet can easily execute malicious code .

Use of applets

In addition to many uses in in-house software, applets are also used in software that is widely used by the public. Examples for this are:

  • Photo service providers who handle the upload and processing with applets,

See also

  • In contrast to the applet, a “ Java application ” runs as an independent Java program outside of the browser. However, the applet that works in the browser can also be called up appropriately from an independent application and thus the applet can be used on several sides.

Web links

Individual evidence

  1. ^ Daniil Titov: Deprecate the Applet API. Retrieved March 15, 2017 .
  2. JDK 11 Release Notes, Important Changes, and Information. Retrieved September 7, 2019 .
  3. Java Plug-in Technology
  4. Java Kernel FAQ