Java_Programming_Chapter_2
Java_Programming_Chapter_2
Java Applet
Instructor Name
Date
Introduction to Java Applets
• Java applets are small applications designed to
be embedded in web pages.
• They are executed within a browser using a
Java plugin.
Java Applets Characteristics
• Characteristics of Java applets include:
• - Platform-independent
• - Can be embedded in HTML pages
• - Runs in a browser environment
Java Applet Life Cycle
• The applet life cycle consists of the following
methods:
• - init()
• - start()
• - stop()
• - destroy()
Creating a Simple Java Applet
• A basic Java applet example:
• import java.applet.Applet;
• import java.awt.Graphics;
• public class MyApplet extends Applet {
• public void paint(Graphics g) {
• g.drawString("Hello, World!", 20, 30);
• }
• }
Applets in HTML
• Java applets can be embedded in HTML using
the <applet> tag:
• <applet code="MyApplet.class" width="300"
height="300"></applet>
Java Applets vs Java Applications
• Key differences between applets and
applications:
• - Applets run in a web browser, applications
run on the desktop.
• - Applets require a browser plugin,
applications do not.
Advantages of Java Applets
• Advantages of Java Applets:
• - Platform independence
• - Easy to integrate with web pages
• - Can interact with web page elements
Disadvantages of Java Applets
• Disadvantages of Java Applets:
• - Security restrictions
• - Browser compatibility issues
• - Declining use due to better alternatives
Applet Security Model
• Java applets are executed in a sandbox
environment to restrict access to the local file
system and network.
• - Signed applets can request extended
permissions.