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

Java Applet

Java applets were small programs that could be embedded in web pages and run in web browsers using the Java plugin. However, they have been deprecated due to security concerns and the evolution of modern web technologies like JavaScript. Developers now use JavaScript frameworks instead of applets to create interactive web applications.

Uploaded by

rajeshchoudhary
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Java Applet

Java applets were small programs that could be embedded in web pages and run in web browsers using the Java plugin. However, they have been deprecated due to security concerns and the evolution of modern web technologies like JavaScript. Developers now use JavaScript frameworks instead of applets to create interactive web applications.

Uploaded by

rajeshchoudhary
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

JAVA APPLETS

Java applets were small applications written in the Java programming language that could be
embedded in web pages and run in a web browser. However, it's important to note that Java
applets have largely fallen out of favor and have been deprecated in modern web development
due to security concerns and the evolution of web technologies.

1. Introduction: Java applets were introduced in the mid-1990s as a way to make web pages
interactive and dynamic. They were designed to run in a secure sandboxed environment within a
web browser.
2. Applet Tags: To embed a Java applet in a web page, an HTML applet tag was used. The applet
tag specified the applet class, various attributes, and provided a means to pass parameters to the
applet.

<applet code="MyApplet.class" width="300" height="200">

<!-- Optional parameters here -->

</applet>

1. Java Plugin: For a web browser to run Java applets, users needed to have the Java plugin
installed. Browsers provided support for the Java plugin, allowing applets to run.
2. Security: Java applets were executed within a sandbox to prevent them from accessing the user's
file system or performing potentially malicious actions. However, security vulnerabilities
emerged over time, leading to their decline in popularity.
3. Limited User Interface: Applets provided a graphical user interface that allowed developers to
create interactive elements, but they were limited in terms of the richness and complexity of the
UI compared to modern web technologies.
4. Lifecycle: Java applets had a lifecycle that included methods like init(), start(), stop(), and
destroy(). These methods allowed developers to control the applet's behavior at different points
in its execution.
5. Interactivity: Applets could interact with the web page on which they were embedded and make
network requests. They were often used for tasks like form validation, simple games, and data
visualization.
6. Applet Security Policy: Developers could specify a security policy for applets. This policy
defined the level of access an applet had to system resources. Applets requesting broader
permissions needed to be signed with a certificate.
7. Deprecation: Java applets have been deprecated in modern web development. Major web
browsers no longer support the Java plugin, and applet technology is considered outdated.
Developers have moved to alternative web technologies like HTML5, JavaScript, and CSS for
creating interactive web applications.
8. Alternatives: To achieve similar functionality as Java applets in the modern web, developers use
JavaScript frameworks and libraries, such as React, Angular, or Vue.js, along with HTML5 and
CSS. These technologies offer more flexibility, security, and better cross-browser compatibility.

Advantage of Applet

There are many advantages of applet. They are as follows:

o It works at client side so less response time.


o Secured
o It can be executed by browsers running under many plateforms, including Linux, Windows, Mac Os etc.

Drawback of Applet

o Plugin is required at client browser to execute applet.

Lifecycle of Java Applet

1. Applet is initialized.
2. Applet is started.
3. Applet is painted.
4. Applet is stopped.
5. Applet is destroyed.

java.applet.Applet class

For creating any applet java.applet.Applet class must be inherited. It provides 4 life cycle methods of applet.

1. public void init(): is used to initialized the Applet. It is invoked only once.
2. public void start(): is invoked after the init() method or browser is maximized. It is used to start the Applet.
3. public void stop(): is used to stop the Applet. It is invoked when Applet is stop or browser is minimized.
4. public void destroy(): is used to destroy the Applet. It is invoked only once.

/First.java
import java.applet.Applet;
import java.awt.Graphics;
public class First extends Applet{

public void paint(Graphics g){


g.drawString("welcome",150,150);
}

myapplet.html

<html>
<body>
<applet code="First.class" width="300" height="300">
</applet>
</body>
</html>

1. //First.java
2. import java.applet.Applet;
3. import java.awt.Graphics;
4. public class First extends Applet{
5.
6. public void paint(Graphics g){
7. g.drawString("welcome to applet",150,150);
8. }
9.
10. }
11. /*
12. <applet code="First.class" width="300" height="300">
13. </applet>
14. */
15. c:\>javac First.java
16. c:\>appletviewer First.java

You might also like