Breaking

Java Applet

                                       

                                      java applet

Java Applet is a small java program that is primarily used in internet computing. A Java applet, like any application program, accepts user input, create animation, and play interactive games. Java applet always run inside the web browser.

Example of applet by HTML:-

file name=Helloworld.java


 import java.awt.color;

 import java.awt.graphics;
 import java.applet.Applet;

public class Helloworld extends Applet
{
public void paint(Graphics g) 
{
g.setColor(color.Red);
g.setBackground(color.Black);
g.drawString("Hello, World",20,20);
}
}

An applet is compiled by Javac fileName.Applet.

javac Helloworld.Applet 


Helloapplet.html

 <html>
<head><title>hello applet</title>
</head>
<body>
 <applet code="Helloworld.java" width="200" height="200"></applet>
</body>
</html>

Java has revolutionized the way the internet user retrieve and use documents on the worldwide network. Java has enabled them to create and usefully interactive multimedia web documents. A web page can now contain not only a simple text or a static image but also a Java applet which, when run, can produce graphics, sounds, and moving images. Java applets therefor have begun to make a significant impact on WWW.

                      Local and Remote Applet  

We can embed applets into Web pages in two ways. One, we can write over own applets and embed them into Web pages. we can easily download an applet from a remote computer system through the web page.
       An applet is developed in the local system and stored in a local system is known as a local applet. When a Web page is trying to find a local applet, it does not need to use the internet and therefore the local system does not require an Internet connection.
       A remote applet can develop anyone and stored on a remote computer through the Internet. If our system is connected to the Internet, we can download the remote applet into a system via the Internet.
     To locate and load a remote applet, we must know the address of applet in the Web. This is called a Uniform Resource Locator (URL) address.


Example of appletviewer:-

//Helloapplet
 import java.awt.color;
 import java.awt.graphics;
 import java.applet.Applet;

public class helloapplet extends Applet
{
public void paint(Graphics g) 
g.drawString("Hello applet",200,200);
}

/*

 <applet code="Helloapplet.java" width="200" height="200"></applet>
*/

Applet viewer is compiled by 

javac Helloapplet.java

Run by

Appletviewer Helloapplet.java 

Advantages of Java Applet:-

  • It is only working from client side and too responsive.

  • It is also secured.

  • java applet is executed on a system by using browsers.

                  How Applets Differ From Applications

  The applets and stand-alone applications both are Java programs, there are small differences between them. Applets are not full-featured application programs. They usually return to accomplish a small task or a component of a task. Since they are usually designed for use on the internet, they impose certain limitation restrictions in their design.

  •  An Applet does not use the main() method for the execution of the program. Applets, we load, automatically call certain methods of Applet class to start and execute the applet code.
  •  applets cannot be run independently.
  •  Applets are always run from inside a Web page using HTML tag.
  • Applets cannot read or write the files.
  • Applets cannot communicate with others servers on the network.
  • Applets can't run the program from any local computer.
  • Applets are restricted from using libraries.