[Go to site: main page, start]

0% found this document useful (0 votes)
26 views10 pages

Understanding Java Applets Basics

Uploaded by

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

Understanding Java Applets Basics

Uploaded by

dejenehundaol91
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

School of Informatics

Department of Computer Science

Chapter 2 Java Applet

Compiled by Dawit Uta. (M. Tech.)


Computer Science Department, WSU
website address: [Link]
2 Course outline

Chapter 2 Java Applet


2.1. Overview of Java Applets
2.2. Java Applets Vs Java Application
Overview of Applet
3
 Java programs that run on the Web are called applets;

 An applet is a small java program that are not stand-alone programs. Instead, they run
within either a web browser or an applet viewer.

 Java can work within the World Wide Web of computers via browsers, such as Netscape and
Internet Explorer, google chrome etc. Applets are usually run from web browsers.

 The JVM is able to run a Java program for the particular computer on which it is running.

 An applet is embedded in an HTML page using the APPLET or OBJECT tag and hosted on a
web server.
 Applets provide sound, graphics and animation in various forms and formats for web pages.
Overview of Applet cont…
4

 Applets are used to make the website more dynamic and entertaining, also used in
games, gaming consoles, commercial websites, learning tools and many more.

 All applets are sub-classes of the [Link] class

 Swing provides a newer subclass of the Applet class called [Link] so


more functionality is inherited by extending the JApplet class

 JDK provides a standard applet viewer tool called applet viewer.

 In general, execution of an applet does not begin at main() method.

 Output of an applet window is not performed by [Link](). Rather it is


handled with various AWT methods, such as drawString().
Life cycle of an applet :
5

 It is important to understand the order in which the various


methods shown here in the image are called.
 When an applet begins, the following methods are called, in
this sequence:
[Link]( )
[Link]( )
[Link]( )

 When an applet is terminated, the following sequence of


method calls takes place:
[Link]( )
[Link]( )
Life cycle of an applet cont…
6

 init(): This method is intended for whatever initialization is needed for your applet. It is
called after the param tags inside the applet tag have been processed.
 start(): This method is automatically called after the browser calls the init() method. It is
also called whenever the user returns to the page containing the applet after having gone
off to other pages.
 stop(): This method is automatically called when the user moves off the page on which
the applet sits. It can, therefore, be called repeatedly in the same applet.

 destroy(): This method is only called when the browser shuts down normally. Because
applets are meant to live on an HTML page, you should not normally leave resources
behind after a user leaves the page that contains the applet.
7

 paint(): is invoked immediately after the start() method, and also any time the applet
needs to repaint itself in the browser. The paint() method is actually inherited from the
[Link]

 There many types of web applications and numerous ways in which applets may be
applied.
Java Applets Vs Java Application
8
Java Applets Example

9 import [Link].*;
import [Link].*;
public class HelloWorldApplet extends Applet {
public void paint (Graphics g) {
[Link] ("Hello World This is First Java Applet Program", 10, 50); } }

To run the applet program


javac [Link]
appletviewer [Link]

Save this html as “[Link]”


10

Java Applets are Obsolete/depricated


 There are two distinct ways in which applets have been deprecated:
The applet element was deprecated in HTML 4.01 and rendered
entirely obsolete by HTML5.
 Modern web technologies like JavaScript, HTML5, and CSS3 have
largely replaced Java Applets for creating interactive web content.

End of Chapter Two

Common questions

Powered by AI

The transition to HTML5 has dramatically changed animation handling by utilizing the <canvas> element for 2D drawing and CSS animations for style transitions, removing the need for Java plugins. HTML5 provides native browser support for complex animations, allowing developers to create seamless, hardware-accelerated animations that are more performant and consistent across devices than Java Applets could achieve. This transition has led to more responsive and visually appealing animations directly integrated into web pages, enhancing user engagement .

The deprecation of the <APPLET> tag in HTML 4.01, and its complete removal in HTML5, marked a significant shift in web development towards more secure, efficient, and compatible technologies. It signaled a move away from plugin-based content delivery towards using native browser capabilities through technologies such as HTML5 canvas for graphics, which improve mobile device compatibility and reduce security risks inherent in running Java Applets on the client side .

The Java Applet lifecycle is crucial in managing animations and sounds efficiently within web browsers. The 'init()' method sets up necessary resources; 'start()' begins the animation or audio playback; 'paint()' ensures graphical updates, and 'stop()' halts these processes when the user navigates away. This method sequence allows applets to load quickly, respond dynamically, and politely release resources when not in use, supporting smooth multimedia presentations over the web .

The 'init()' method in Java Applets is crucial for setting up the applet's runtime environment and resources before it starts executing or displaying anything. It prepares parameters like graphics and audio components necessary for the applet's functionality. Unlike the 'main()' method in Java Applications, which serves as the entry point and handles the entire application logic, 'init()' solely focuses on resource initialization and RMI connection setups if required. This distinction highlights Applets' dependency on the browser's lifecycle .

Java Applets are specifically designed to run within a web browser or applet viewer, whereas Java Applications are standalone programs that run locally on the device without requiring a browser. The key difference lies in their embedding and execution environment: Applets are embedded in HTML pages and require a JVM compatible with the browser, while Applications operate independently and have direct access to system resources through the local JVM. This means that Applets are limited by browser security restrictions and HTML markup, which impacts their interactivity and integration with web content compared to Applications that can leverage full system capabilities .

The 'paint()' method in Java Applets impacts user experience significantly by directly drawing graphics to the applet's window, enabling interactive and visually rich content in web environments. This differs from typical console-based output, which solely involves text, by leveraging graphical components such as images, shapes, and complex UI elements. This capacity for rich, event-driven rendering allows applets to provide dynamic and engaging interfaces that are not possible with console output .

Modern web technologies such as JavaScript, HTML5, and CSS3 have replaced Java Applets because they provide enhanced security, are lightweight, and allow for greater interactivity directly within the web browser without needing additional plugins. These technologies are more suitable for today's web environment due to their seamless integration capabilities, wide browser support, and the ability to create dynamic and interactive webpages efficiently using standard web protocols without security concerns associated with applets .

Java Applets faced challenges like security vulnerabilities, dependency on browser plugins, and inconsistent browser support which hindered their widespread adoption. Modern web technologies have overcome these obstacles by utilizing native browser capabilities that eliminate plugin requirements, enhance security through regular updates, and ensure compatibility across all major browsers. Technologies like HTML5 and CSS3 provide robust, flexible, and secure frameworks for developing interactive content that Java Applets could not, thereby paving the way for their obsolescence .

The execution lifecycle of a Java Applet is designed to efficiently manage resources by ensuring that resources are initialized, used, and disposed of in a controlled manner. The lifecycle consists of the following steps: 'init()' is called for initialization, preparing resources; 'start()' is called to start the execution; 'paint()' is invoked to render the content; 'stop()' is called when the user navigates away, conserving resources; and 'destroy()' is executed when the applet is being removed or the browser is closing, ensuring proper resource release. This sequence allows web resources to be effectively managed by only engaging them when necessary and releasing them otherwise .

Java Applets were historically seen as less secure because they operated within browsers with limited sandboxing. This made them susceptible to security vulnerabilities, particularly when dealing with unsigned code. Modern web technologies like JavaScript, HTML5, and CSS3, however, are natively supported by browsers and benefit from more robust and automatic security updates. As these technologies do not require external plugins, they pose fewer security risks which influenced the transition away from applets in favor of safer, plugin-free web development .

You might also like