Java Applets were a revolutionary means of deploying dynamic web applications directly to the browser, utilizing the Java language. Much before the rise of modern front-end frameworks like React or Angular, Java Applets provided developers with the capability to include dynamic, secure, platform-agnostic elements in HTML pages. So, what is an applet in Java? What does it do, and why has the popularity of Java Applets faded in recent times?
In this in-depth tutorial, you will learn the entire concept of Java applets, their lifecycle, architecture, usage scenarios, and why they have been deprecated. You are either a beginner in Java, a student of computer science, or a developer looking to study for interviews – this blog shall give you a good understanding of the concept of an applet in Java, its pros and cons, as well as its comparison with the modern alternatives.
What is an Applet in Java?
A Java Applet is a small Java program that is included in a web page and runs in the environment of a browser or an applet viewer. Unlike standard Java applications, an applet does not have a main() method, but instead extends the class java.applet.Applet or javax.swing.JApplet (for Swing-based applets) and implements its lifecycle methods. Applets first existed in Java 1.0 (1995) to provide dynamic, interactive material for web pages. They execute on the client-side within a Java Virtual Machine (JVM) plugin or applet viewer. In reality, an applet’s code is downloaded from a server when the user opens the page, and the browser (through a plugin) instantiates the applet class and calls its methods
Applets came to stand for the support of simple GUI operations (say, animations, games or calculators) with AWT/Swing components within the browser itself. The code for the applet is embedded in HTML through the <applet> or <object> tag. Since the applets execute within the browser, they provide Java GUI programming within web pages.
History of Java Applets
Java applets have a long history on the web. They were introduced with Java 1.0 in 1995 as one of the first ways to add interactivity beyond basic HTML.
In 1997, Sun Microsystems released the HotJava browser, the first browser to support applets, showcasing their potential for interactive web pages.
During the late 1990s and early 2000s, applets were widely used for things like simple games, animations, forms, and calculators on websites. For the better part of a decade, they were “the internet’s outlet for creative interactivity”.
However, their popularity diminished due to several factors. Security issues, the requirement to install a Java plugin, and competition from other web technologies like JavaScript, Adobe Flash, and HTML5 diminished their usage.
Major browsers stopped supporting them: Google Chrome (v45+ released in 2015) dropped the NPAPI plugin architecture that disabled Java applets. Similarly, Firefox and other browsers followed suit.
Oracle formally deprecated the Applet API in Java 9 and later, citing that the usage of applets is no longer common.
By 2025, applets are practically obsolete in modern web development – used primarily in outdated systems or as an example of Java’s outdated client-side technology
Java Applet Architecture
The structure of a Java applet is composed of various components:
- Applet Class: All applets are subclasses of java.applet.Applet (or javax.swing.JApplet for Swing). The class of the applet has methods that are invoked by the browser or the viewer to control the life cycle of the applet. For instance, init(), start(), stop(), destroy(), and the paint(Graphics) method inherited from AWT are called at the right moment.
- Applet Viewer/Java Browser: A Java-capable browser or the included appletviewer from the JDK loads the applet class from the server and instantiates a JVM or plug-in process. The plugin architecture for the browser (previously NPAPI) links the HTML <applet> tag to the Java code. The lifecycle methods are invoked by the browser upon loading to begin, stop, or destroy the applet.
- HTML Integration: On the web page, an applet is included with the <applet> tag (or <object> in HTML4). The tag describes the class file, the size, and the parameters of the applet. During the page load, the JVM plugin loads the tag, downloads the .class (or .jar) files, and creates the applet.
- Security Sandbox: Applets run in a sandbox by default to secure the user’s system. Unsigned applets are only capable of performing restricted operations (e.g., opening network connections to the server the applet originated from). Signed applets have the capability to request greater privileges, provided that the user consents to them.
This architecture makes the applet essentially a client-side GUI program resident in the browser. It has the potential to utilize Java’s GUI libraries (AWT or Swing) to render graphics, respond to user events, and so on – essentially moving Java GUI programming to the web page.
Types of Java Applets
Java applets may be categorized in several ways:
Based on Storage:
- Local Applets: The class files of the applet are kept on the same machine where the web server is located (under direct control). The browser loads it from a local location.
- Remote Applets: The code for the applet is hosted on a remote server on the Internet. The browser has to download it from the network on opening the page.
According to the API:
- AWT Applet (java.applet.Applet): The traditional type, based on Java’s Abstract Window Toolkit (AWT) for GUI elements
- Swing Applet (javax.swing.JApplet): A derivative class utilizing Swing, which is included in the Java Foundation Classes, for richer GUI elements. Swing applets are more feature-rich and look more modern. Swing-based applets (JApplets) are practically more prevalent today than are pure AWT ones.
Every applet executes in the browser’s JVM environment, but the primary distinction is the toolkit (AWT vs Swing). These are both effectively outdated in modern tech but demonstrate that applets could have utilized Java’s native GUI libraries.
Lifecycle of a Java Applet
The life cycle of an applet is the set of calls the browser makes to the applet throughout its lifetime. There are five primary stages, the respective methods of which are in the java.applet.Applet class:
- init(): Called only once at the time the applet is loaded. It is for performing the initialization process (e.g., configure the UI, load the resources).
- start(): Invoked after init(), and also upon every user revisit or page reload. This is where the applet begins or resumes running.
- paint(Graphics g): Called to paint graphics to the applet window. Invoked after start() and whenever the area of the applet has to be redrawn (e.g., uncovered, resized). The paint() function is provided with a Graphics context to draw shapes, strings, etc.
- stop(): Invoked when the user leaves the page or otherwise terminates the applet. It should stop whatever activity is currently running. When the user returns, start() is invoked again.
- destroy(): Invoked whenever the browser closes or the applet is unloaded for good. Should release resources. Following destroy(), the applet cannot be restarted.
Figure: Java applet life-cycle (init -> start -> paint -> stop -> destroy). The browser invokes start() after init(). The paint() function paints whenever the content is needed. stop() is invoked on leaving the page, then destroy() upon the unload of the applet (when the browser is quit).
For instance, upon the first opening of an applet’s page in the browser, the browser instantiates the applet object and invokes init(), followed by start(). The applet may initialize in init(), and start threads or begin animation. As soon as the applet has to draw, the browser invokes paint(). If the user navigates away from the page, the browser invokes stop() (pausing the applet). If the user closes the browser, destroy() is called. This pattern guarantees that the resources are properly managed.
Every lifecycle function can be overridden within your applet code. A basic applet may override just paint() to render something. Here is an outline overview (not code):
public class MyApplet extends Applet {
public void init() {
// Initialization code here (called once)
}
public void start() {
// Called each time the applet becomes visible
}
public void paint(Graphics g) {
// Draw something on the screen
g.drawString("Hello from Applet!", 50, 25);
}
public void stop() {
// Pause activities here
}
public void destroy() {
// Cleanup here
}
}
The lifecycle is different from that of a Java program, which just starts with main() and continues until it terminates. The lifecycle of an applet is controlled by the browser, not the main() class.
Java Applet Example: Hello World
One classic example is a “Hello World” applet. Such an applet writes a string onto the page. Here is an example using AWT:
import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorldApplet extends Applet {
public void init() {
// Optional: initialization code
}
public void paint(Graphics g) {
// Draw a string at position (50, 50)
g.drawString("Hello, World Applet!", 50, 50);
}
}
To include this applet in an HTML document, you would have used the <applet> tag (in HTML4; HTML5 deprecated <applet>). For instance:
<html>
<body>
<h3>My HelloWorld Applet</h3>
<applet code="HelloWorldApplet.class" width="200" height="100">
Your browser does not support Java applets.
</applet>
</body>
</html>
Output:
Here, the code “HelloWorldApplet.class” instructs the browser to load the class that has been compiled. When the HTML document is loaded in a Java-capable browser (or using appletviewer HelloWorld.html), the applet runs and invokes its paint() function, writing “Hello, World Applet!” at the requested coordinates.
Note: Since the Applets are deprecated in modern Java programming, you must need to have JDK 8 or below version in order to execute this code.
Key Takeaway: The source for the applet is compiled using javac HelloWorldApplet.java. The HelloWorldApplet.class is generated and put on the web server (or the same directory). The HTML <applet> tag causes the browser plug-in for Java to download and execute.
Java Applet vs Java Application
One common point of confusion is the difference between a Java applet and a Java application. Here are the key distinctions:
| Feature |
Java Applet |
Java Application |
| Runs In |
Web browser (with Java plugin) |
Standalone desktop environment |
| Execution |
Requires HTML and browser support |
Executes via main() method |
| User Interaction |
Limited to UI in a browser window |
Full access to system resources and UI |
| Security |
Runs in sandbox (restricted access) |
Has full system access (based on permissions) |
| Use Case |
Embedded in web pages for lightweight tasks |
General-purpose applications and tools |
| Availability |
Deprecated and not supported in modern browsers |
Widely used in modern Java development |
In simple words, you can say that “A Java applet “is a special type of small Java program that is included inside a web page and needs to be run with a browser or appletviewer. A regular Java application, on the other hand, runs on any machine that has a JVM and invokes main() to begin.”
Advantages of Java Applets
Java applets had several advantages when they were popular:
- Platform Independent: Operates on any Operating System using a Java-capable browser.
- Secure Execution: Executes within a sandbox, reducing system risk.
- GUI Support: Rich graphical user interface components are supported.
- Web-friendly: Simple to download and run online.
- No Installation Required: Executes in the browser without the need for setup.
- Compact: Applets are light in weight and have minimal download time.
- Easy Animation: Supports simple graphics and real-time animation.
- Network Support: Can talk to the server from the client side.
- Reusable Code: Java classes can be reused in multiple applets.
- Multithreading: Enables concurrent execution for smoother user interface and operations.
Disadvantages and Limitations of Java Applets
Despite their advantages, applets had serious disadvantages:
- Browser Compatibility: Does not support modern browsers like Chrome or Edge.
- Performance Problem: Slower compared to native applications due to VM overhead.
- Security Restrictions: Restricted control of system facilities.
- Needs Plugin: Requires Java plugin, but this is deprecated.
- Outdated Technology: Replaced with newer web technologies such as JavaScript and HTML5.
- Security Alerts: Too many browser warnings create distrust and usability issues.
- Performance Bottlenecks: Slower for JVM startup time and sandbox limitations.
- Compatibility Problems: Varies with operating systems and versions of the browser.
- More Challenging Debugging: Debugging applets is harder than that of normal Java applications.
- Relplaced by Modern Tools: Applets have been made outdated by technologies like HTML5, JavaScript, and WebAssembly.
Java Applet Security and Sandbox
Security was a primary focus for applets. Unsigned applets execute in a strict sandbox with the following limitations:
- Restricted Networking: Applets can open only network connections back to the originating server. They cannot communicate with third-party servers or to arbitrary IP addresses.
- No Local File System: Applets are unable to read or write the machine’s local files. Neither can they load native code libraries nor modify the system clipboard or the system’s printers.
- Restricted System Access: Applets are not permitted to modify the system’s SecurityManager, create custom class loaders, or read some JVM system properties.
- Limited Execution: They are unable to initiate any local executable or launch processes on the client, nor may they call native (C/C++) code.
- User Confirmation: To even access this sandbox, the user usually has to agree to run the applet (particularly if signed).
A signed applet using a legitimate certificate is also able to request more rights (it becomes a “privileged” applet). But the user is first asked to trust the certificate. If the user refuses, the applet is run in the sandbox.
Security limitations made the applets safer in theory, but also annoying for developers and users. Most organisations disable plugins altogether to mitigate vulnerabilities. Practical complexities involving signing and permissions were one reason why the browser makers ultimately abandoned plugin support.
Current Relevance of Java Applets
As of 2025, Java applets are practically obsolete in deployment. The Java 9+ platform deprioritized the Applet API itself, and mainstream browsers block applets by default. Oracle’s official documentation explains that both the Applet API and Java Plug-in are deprecated, but advises moving to Java Web Start or stand-alone applications.
For example, Oracle states:
“Although available and supported in JDK 8, the Applet API and the Java Plug-in are marked as deprecated in preparation for removal. Instead of applets, consider alternatives such as Java Web Start or self-contained applications.”
Chrome’s developer site confirms: “Chrome no longer supports NPAPI (technology required for Java applets). The Java Plugin… does not work on these browsers anymore.” Similarly, Firefox and Edge have ended support.
For Java development on the Web, other technologies have dominated. JavaServer Pages (JSP), Servlets, JavaScript frameworks, and HTML5 offer web UIs that are interactive but are not based on applets. Rich client applications are supported by Java Web Start (and the open-source alternative, OpenWebStart), enabling exposure of Java applications through JNLP outside the browser. Most older applets have been re-implemented in the form of Java Web Start applications or entire desktop applications.
In short, you would not write a project in 2025 using an applet. They are only useful now as a historical notion or for older systems. For students in India (or anywhere else), knowing about applets can assist in the exam or learning about the past of Java, but other topics are the focus for modern Java programming.
Running Java Applets
Though the browser support has been dropped to a large extent, you can also run the applets for learning or backwards compatibility reasons using the appletviewer utility provided with the JDK (up to Java version 8). For example, having compiled HelloWorldApplet.java, you write an HTML file containing the <applet> tag (as mentioned above). Then you open a command prompt and execute:
appletviewer HelloWorld.html
This launches the applet in a window without a full browser.
This opens the applet in a window without the full browser. With an actual browser, the steps are the same: put the .class file on a web server, reference the <applet> tag to it, and open the page in a Java-capable browser. But keep in mind that recent browsers can only run applets with a workaround (or just use old Internet Explorer).
Note: If you are using the appletviewer or a Java browser, ensure that your Java settings permit unsigned code or correctly sign the applet.
Conclusion
In short, a Java Applet is old technology: a Java program that executes inside a browser plug-in for a web page using the java.applet.Applet API. We established what applets are, reviewed their history and structure, and outlined their life cycle methods (init(), start(), paint(), stop(), destroy()). We also analyzed how applets differ from stand-alone Java applications in terms of execution, security, and GUI. We also enumerated the advantages (browser GUI cross-platforming) and disadvantages (security limitations, loss of browser support) of applets. Most importantly, modern web development has advanced beyond the level of applets: the Java plug-in is no longer included in mainstream browsers, and the applet API is deprecated.
Java Applets – FAQs
What is the purpose of the Applet class?
The java.applet.Applet class is the foundation class for writing applets. It declares methods such as init(), start(), etc., to be overridden. It also provides facilities like image loading, audio playing, etc., to access the parameters passed to an applet. All applets are subclasses of this class..
How many types of applets are there?
There are two main types, primarily: Local vs Remote (location where the code is kept) and AWT vs Swing (whether the applet is extending Applet or JApplet). Local applets are on the same machine where the page is, remote applets are hosted on a web server. JApplet (Swing applet) is the choice nowadays over the old AWT Applet.
What is the difference between an applet and an application in Java?
The major difference is the context of execution. An applet is hosted inside a web page and executed within a browser (no main() routine, restricted permissions), while a Java application is independent (requires main(), unrestricted system access). Applets have a special lifecycle, are unable to read local files without special arrangements, and require a browser plugin or viewer.
Are Java applets still used?
Not in today’s development. The Applet API is deprecated since Java 9, and the plugins have been dropped from the browsers. The Applets persist solely on old systems or for instructional purposes. Interactive features on the web are now done using technologies such as JavaScript, HTML5, or other web frameworks.