For security reasons applets are limited in what they can accomplish, because they can be executed by anybody via the Internet.

The functionality applets inherit from the Applet class ranges from communication with the browser to the ability to present a graphical user interface (GUI).
Example, "Hello World" as applet:
import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorldApplet extends Applet
{
public void paint(Graphics g)
{
g.drawString("Hello world!", 50, 25);
}
}
Or using Swing:
import javax.swing.*;
import java.awt.*;
public class HelloWorldApplet extends JApplet
{
public void init() {
getContentPane().add(new JLabel("Hello World!"));
}
}
The HelloWorld applet implements just one method, the paint method.
The Graphics object passed to the paint method represents the applet's on-screen drawing context.
When a Java-capable browser loads a page containing an applet, the browser sends a request to the applet, telling the applet to initialize itself and start executing.
An applet is not restricted to the applet-subclass, it can define additional custom classes.
Instead every applet must implement at least one of the following methods:
paint(): Called whenever the applet must paint itself. For animations paint is called continuously (via repaint) from an animation thread.
init(): Called to perform first-time initialization of the applet.
start(): Called every time the applet moves into sight on the Web browser to allow the applet to start up its normal operations (especially those that are shut off by stop()). It is also called after init().
Applets can implement two more methods that the browser calls when a major event occurs (such as leaving the applet's page):
stop(): Called every time the applet moves out of sight on the Web browser to allow the applet to shut off expensive operations. It is also called right before destroy().
destroy(): Called when the applet is being unloaded from the page to perform final release of resources.
Applets can implement any number of other methods, as well.
If you include an applet twice in one page, the browser loads the class file once and creates two instances of the class.
Starting from HTML 4.0 the <APPLET> tag is deprecated, it is replaced by <OBJECT>. But almost all browsers still understand <APPLET>, whereas <OBJECT> is not yet widely spread.
Alternatively to a browser you can
invoke Sun's 'appletviewer'
with the command:
appletviewer HelloWorldApplet.html
An applet cannot touch the local disk.
This means writing or reading, since you would not want an applet
to read and transmit private information over the Internet.
It also cannot not execute local files.
An applet cannot make network connections except to the host that it came from.
Java offers digital signing for applets. Many applet restrictions are relaxed when you choose to allow signed applets (those signed by a trusted source) to have access to your machine.
Each browser has a SecurityManager object that implements its security policies. When a SecurityManager detects a violation, it throws a SecurityException. Your applet can catch this SecurityException and react appropriately.
An applet uses the 'getParameter()' method to
access parameter values:
import java.applet.*;
import java.awt.*;
public class GetParameterApplet extends Applet
{
private String firstName;
public void init()
{
firstName = getParameter( "firstname" );
}
public void paint(Graphics g)
{
String Greetings;
Greetings = "Hello "+firstName+" !";
Font big = new Font("Serif", Font.BOLD, 24);
g.setFont( big );
g.drawString( Greetings, 30, 20 );
}
}
...turn the page to servlets.