What Is Applet in Java With Example: A Beginner’s Guide

Robert Jul 13, 2026

Applets in Java have often been confused with applications, but they are two distinct entities. Java applets are programs written in the Java programming language that can be embedded in HTML pages and run in a web browser. Unlike applications, applets are typically used for client-side processing, while applications are used for server-side processing. Let's delve into the world of Java applets, understand their relevance, and explore a basic example.

the life cycle of an applet is shown in this graphic above it's caption
the life cycle of an applet is shown in this graphic above it's caption

Before proceeding, it's crucial to understand that Java applets need a Java-compatible browser to run. However, due to security issues, many modern browsers have phased out applet support. Nevertheless, they remain an essential part of Java programming history and contribute to its foundational understanding.

Java Collection Framework: ArrayList Explained Visually
Java Collection Framework: ArrayList Explained Visually

What are Java Applets?

A Java applet is a Java program that is embedded in an HTML page and executed on the client-side. It is declared in HTML using the `` tag, with attributes defining parameters like its code and size. Java applets can perform various tasks, such as displaying graphics, playing animations, or interacting with users through a graphical user interface (GUI).

what is applet in java with example
what is applet in java with example

Several components work together to execute Java applets. The web browser loads the HTML page, which triggers the applet runner (also called the plugin or Java Runtime Environment - JRE) to run the applet code. The applet runner executes the applet's bytecode using the Java Virtual Machine (JVM), while the applet interacts with the user via the browser's User Interface.

Advantages of Java Applets

Java Cheatsheet
Java Cheatsheet

Java applets offer several advantages over plain HTML. They can draw complex graphical scenes, update displays without refreshing the entire page, and respond to user events more efficiently than JavaScript. Additionally, applets can be reused across different web pages without recompiling or redeploying, making them versatile and highly reusable.

Moreover, applets can access the Java API, which provides a wealth of tools and functionalities that can significantly ease and accelerate the development process. However, one notable disadvantage is that they require a Java-compatible browser and a compatible JRE to run, which may limit their accessibility and user base.

Components of a Java Applet

an abstract class with different types of text
an abstract class with different types of text

A basic Java applet consists of three main components:

  • Applet Class: The main class containing the applet's code, extending one of the Java applet classes, usually `java.applet.Applet` or its subclasses like `java.appletletlet` or `javax.swing.JApplet`.
  • Web Browser: The client-side software that hosts and loads the applet, providing the necessary environment for its execution.
  • Java Runtime Environment (JRE): The software that interprets the applet's bytecode, enabling the applet to run and interact with the user.

Java Applet Example

☕ What Is Java? | Simple Guide for Beginners 🚀
☕ What Is Java? | Simple Guide for Beginners 🚀

The following example showcases a simple "Hello, World!" Java applet. Save this code as `HelloWorld.java` and compile it using the `javac` command.

```java import java.awt.*; import java.applet.*; public class HelloWorld extends Applet { public void paint(Graphics g) { g.drawString("Hello, World!", 50, 50); } } ```

Polymorphism in Java Explained | Method Overloading & Overriding Easy Notes
Polymorphism in Java Explained | Method Overloading & Overriding Easy Notes
Java - Linear Search
Java - Linear Search
Why learn java applet technology
Why learn java applet technology
Java Patterns Notes 1
Java Patterns Notes 1
Top 10 Applications of Java in Real World
Top 10 Applications of Java in Real World
JAVA
JAVA
Java Data Types Made Easy for Beginners
Java Data Types Made Easy for Beginners
✅ Java Inheritance Example Explained Simply
✅ Java Inheritance Example Explained Simply
an open book with instructions on how to use the array array in windows and linux
an open book with instructions on how to use the array array in windows and linux
Level Up Your Java 🚀 Intermediate Cheat Sheet You’ll Actually Use
Level Up Your Java 🚀 Intermediate Cheat Sheet You’ll Actually Use
java
java
an image of a computer screen with the words and numbers on it, including two arrows
an image of a computer screen with the words and numbers on it, including two arrows
Class and Object in Java Explained | OOP Concepts for Beginners
Class and Object in Java Explained | OOP Concepts for Beginners
Master Two Pointers Technique 💻 | Java DSA Interview Preparation Guide
Master Two Pointers Technique 💻 | Java DSA Interview Preparation Guide
Java Cheat Sheet: Operators, Scanner & User Input ☕
Java Cheat Sheet: Operators, Scanner & User Input ☕
📚 Java Quick Revision Notes Aesthetic Edition
📚 Java Quick Revision Notes Aesthetic Edition
Inheritance in Java Explained | OOP Concepts for Beginners
Inheritance in Java Explained | OOP Concepts for Beginners
60 Java projects ideas💡
60 Java projects ideas💡
Java if Statement 🚦 | Make Smart Decisions with Code!
Java if Statement 🚦 | Make Smart Decisions with Code!

To run the applet, use the `appletviewer` command followed by the compiled class name (`HelloWorld.class`). Replace `"Hello, World!"` with your desired message, and adjust the `(50, 50)` coordinates to position the text in the applet window.

Remember, security concerns have led to browsers dropping support for Java applets. This example may not run directly in modern web browsers, but it serves as a foundational understanding of Java applets.

Embedding Java Applets in HTML

To embed this applet in an HTML page, use the `` tag with the necessary attributes:

Attribute Description
code The URL of the applet's JAR file or the fully-qualified class name of the applet class.
width The preferred width of the applet in pixels.
height The preferred height of the applet in pixels.

Example:

```html No Applet Support ```

Java applets offer a range of possibilities for client-side Java programming. Although their usage has somewhat declined due to browser security concerns, they remain an integral part of Java's rich history and provide valuable insights into the language's capabilities.

© 2026 Robert Ideas. All rights reserved.