Java Applets

A Java applet is a small application written in Java, and delivered to users in the form of bytecode. The user launches the Java applet from a web page. The Java applet then executes within a Java Virtual Machine (JVM) in a process separate from the web browser itself, yet it can appear in a frame of the web page, in a new application window, or in Sun’s AppletViewer

Example :

import java.applet.Applet;
import java.awt.*;

// Applet code for the "Hello, world!" example.
// This should be saved in a file named as "".
public class FirstApplet extends Applet {
	// This method is mandatory, but can be empty.
	public void init() {

	// This method is mandatory, but can be empty.
	public void stop() {

	// Print a message on the screen (x=10, y=30).
	public void paint(Graphics g) {
		g.drawString("Hello, world", 10, 30);

		// Draws a circle on the screen (x=40, y=30).
		g.drawArc(40, 30, 20, 20, 0, 360);

You can run the above program in eclipse as usual, but in order to see this running in browser we have to make a HTML file and mention .class name of the compiled java(applet) class. as :

<!DOCTYPE html>
        <title>Applet Demo</title>
        <h1>Java applet example</h1>
            <applet code="FirstApplet.class" height="40" width="200">
                First applet !!!

The directory for both files should be same in order to run it here now with above example codes.
open the html file in any browser and you will see applet running.