0% found this document useful (0 votes)
3 views

Applet in Java

An applet is a small Java program that runs within a web browser and is embedded in an HTML page, lacking a main method unlike standalone applications. The applet lifecycle includes methods such as init(), start(), paint(), stop(), and destroy(), and it supports basic graphics operations. While applets have advantages like client-side execution and security, they are now deprecated in favor of modern web technologies like JavaScript and HTML5.

Uploaded by

sahevithe1721
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Applet in Java

An applet is a small Java program that runs within a web browser and is embedded in an HTML page, lacking a main method unlike standalone applications. The applet lifecycle includes methods such as init(), start(), paint(), stop(), and destroy(), and it supports basic graphics operations. While applets have advantages like client-side execution and security, they are now deprecated in favor of modern web technologies like JavaScript and HTML5.

Uploaded by

sahevithe1721
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

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 !!

You might also like