S
Introduction to
Applets
Applets are special Java programs that are embedded within web pages and
executed by a Java-enabled web browser. They provide interactive and dynamic
content, enhancing the user experience on the web.
Definition of Applets
1 Mini Programs 2 Interactive Content 3 Platform
Independent
Applets are small, self- Applets allow for the
contained Java programs creation of interactive and Applets are designed to be
that run within a web dynamic content on web platform-independent,
browser or a Java-enabled pages, such as animations, meaning they can run on
environment. games, and application-like any operating system that
features. supports Java.
Advantages of Applets
Interactivity Platform Independence Security
Applets enable the creation of Applets can run on any platform Applets are designed with a
interactive and dynamic web that has a Java Virtual Machine robust security model, ensuring
content, enhancing user (JVM), providing cross-platform the safety of the host system and
engagement. compatibility. the user's data.
Applet Life Cycle
1 Init()
This method is called when the applet is first loaded, and it is used to initialize the
applet's resources.
2 Start()
The Start() method is called when the applet becomes active and should begin
executing its code.
3 Stop()
The Stop() method is called when the applet should pause its execution, such as
when the user navigates away from the web page.
Applet Security Model
Sandbox Restricted Access
Applets run in a secure "sandbox" environment, Applets have restricted access to the local file
which limits their access to local system resources system, network, and other sensitive areas of the
to ensure the safety of the host system. host system to prevent unauthorized access or
malicious activities.
User Approval Digital Signatures
Before an applet can access resources outside the Applets can be digitally signed to verify their
sandbox, it must obtain the user's approval, origin and integrity, providing an additional layer
ensuring transparency and user control. of security for users.
Embedding Applets in Web Pages
HTML Embedding
Applets are embedded in web pages using the APPLET or OBJECT HTML tags.
Code Attribute
The "code" attribute specifies the location of the applet's class file, which contains
the Java code.
Archive Attribute
The "archive" attribute can be used to specify a JAR file containing the applet's
resources, such as images and other assets.
Applet Communication with JavaScript
JavaScript Interaction Method Calls Data Exchange
Applets can interact with JavaScript can call methods within Applets and JavaScript can
JavaScript code running in the the applet, and the applet can also exchange data, allowing for the
web page, enabling dynamic call JavaScript functions in the creation of interactive and
communication and enhanced web page. responsive web applications.
functionality.
Conclusion and Key Takeaways
1 Interactivity and Dynamism 2 Platform Independence
Applets provide a way to add interactive and Applets are designed to be platform-
dynamic content to web pages, enhancing the independent, allowing them to run on any
user experience. operating system with a Java Virtual Machine.
3 Security and Safety 4 Embedding and Integration
Applets have a robust security model that Applets can be easily embedded in web pages
ensures the safety of the host system and the using HTML tags and can communicate with
user's data. JavaScript for enhanced functionality.