Applets

 APPLET

An applet is a small Internet-based program written in Java for the Web. It can be 

downloaded by any computer. The applet is usually embedded in an HTML page on a Website and can be executed from within a browser.


TYPES OF APPLETS:

Local applet:


A LOCAL applet is the one which is stored on our computer system. When browser tries to access the applet, it is not necessary for our computer to be connected to The Internet.

Remote applet:

A REMOTE applet is the one which is not stored on our computer system and we are required to be connected to the Internet.


Applet life cycle :


The applet lifecycle include the following methods:

init(): This method is called to initialized an applet

start(): This method is called after the initialization of the applet.

stop(): This method can be called multiple times in the life cycle of an Applet.

destroy(): This method is called only once in the life cycle of the applet when applet is destroyed

Explanation:

1. An applet begins its life when the web browser loads its classes and calls its init()

method. Thus, in the init() method you should provide initialization code such as the initialization of variables. Once the initialization is complete, the web browser will call the start() method in the applet. At this point the user can begin interacting with the applet. 

2.If the user moves to other web page while the applet is running then , the web browser will call the applets stop() method so that the applet can take a breather while the user goes off and explores the web some more. 

3. If the user returns to the applet, the web browser will simply call the applet's start() method again and the user will be back into the program. 

4. Finally, if the user decides to quit the web browser, the web browser will free up system resources by killing the applet before it closes. To do so, it will call the applets destroy() method. 

5.You are welcome to override any of the methods in order to provide your own logic. 

For example, you may want to provide logic in the stop() method which performs

some cleanup or save operation. 

6. Finally, you can override destroy() to perform one-time tasks upon program 

completion. One example is cleaning up threads which were started in the init() method


APPLET LIFE CYCLE DIAGRAM

Applet life cycle 


Note:write a program that demonstrates all methods of applet


Difference between applet applications


The differences between applets and applications are given below:

Although both the Applets and stand-alone applications are Java programs, there are 

certain restrictions imposed on Applets due to security concerns, that are listed below:

 Applets don’t use the main() method, but when they are load, automatically call certain methods (init, start, paint, stop, destroy).

 They are embedded inside a web page and executed in browsers.

 They cannot read from or write to the files on local computer.

 They cannot communicate with other servers on the network.

 They cannot run any programs from the local computer.

 They are restricted from using libraries from other languages.

The above restrictions ensures that an Applet cannot doany damage to the local system




Steps Involved In Creating And Executing Java Applets


An applet is a small Internet-based program written in Java for the Web. It can be  downloaded by any computer. The applet is usually embedded in an HTML page on a Web site and can be executed from within a browser.


Steps involved in creating and executing java applets:

1. Build an applet code (.java file)

2. Create an executable file(.class file)

3. Designing a web page using HTML tags.

4. Preparing <APPLET> TAG

5. Incorporating <APPLET> into the web page.

6. Creating HTML file.

7. Testing the applet code

Build an applet code (.java file)

Here we need to import Applet and Graphics classes from the packages java.applet and 

java.awt. we should define a sub class of Applet class.

Here we override the applet methods. And paint() method.

Create an executable file(.class file)

After creating the applet code compile it with javac and create .class

Comments

Popular posts from this blog

History of C language

Lab programs of C

Algorithm Pseudopods Flow-chat