APPLET IN JAVA
NAME : S.VIJAYATHARSHINI
CLASS :1ST CS
SUBJECT: PROGRAMMING IN JAVA
APPLET IN JAVA-AN OVERVIEW
INTRODUCTIO
N
•An applet is a small Java program that runs
inside a web browser.
•It is embedded in an HTML page and executed
using a Java-enabled browser.
•Unlike standalone applications, applets do not
have a main method.
Applet vs. Application
Feature Applet
Application
Execution Runs in browser Runs independently
Main method Not needed Required
Security Restricted access Full access
Usage Web-based Standalone
software
Applet Lifecycle
•init() – Initializes the applet.
•start() – Starts or restarts the applet.
•paint() – Draws graphics on the applet screen.
•stop() – Stops the applet execution.
•destroy() – Cleans up resources before applet is removed.
Simple Java Applet Program java
import java.applet.Applet;
import java.awt.Graphics;
public class MyApplet extends Applet {
public void paint(Graphics g) {
g.drawString("Hello, Applet!", 50, 50);
}
}
This program displays "Hello, Applet!"
on the applet screen.
How to Run an Applet
1.Compile the java file:
javac MyApplet.java
2.Create an HTML
file: <html>
<body>
<applet code="MyApplet.class" width="300"
height="200"></applet>
</body>
</html>
3.Run the applet using:
appletviewer MyApplet.html
Graphics in applet
•Applets support graphics operations like:
•drawLine(), drawRect(), fillOval(), etc.
Example:
public void paint(Graphics g) {
g.drawRect(50, 50, 100, 100);
}
Draws a rectangle in the applet window.
Advantages of Applets
✔ Runs on client-side, reducing
server load
✔ Secure as it runs in a sandbox
✔ No need for installation
Limitations of Applets
❌ Requires Java-enabled
browsers
❌ Limited access to system
resources
❌ Modern web applications prefer
JavaScript & HTML5
Conclusion
Applets were widely used, but they are now
deprecated in Java.
Modern applications use JavaScript & Web
Technologies instead.
However, applets helped shape Java’s web-
based capabilities.
Thank you !!