Applet: An applet is a Java program that can be embedded into a web page. It runs inside the web browser and works at client side. An applet is embedded in an HTML page using the APPLET or OBJECT tag and hosted on a web server. Applets are used to make the web site more dynamic and entertaining.
// A Hello World Applet
// Save file as HelloWorld.java
// HelloWorld class extends Applet
public class HelloWorld extends Applet
// Overriding paint() method
public void paint(Graphics g)
g.drawString("Hello World", 20, 20);
After you enter the source code for HelloWorld.java, compile in the same way that you have been compiling java programs(using javac command). However, running HelloWorld with the java command will generate an error because it is not an application.
Error: Main method not found in class HelloWorld, please define the main method as:
public static void main(String args)
1. All applets are sub-classes (either directly or indirectly) of java.applet.Applet class.
2. Applets are not stand-alone programs. Instead, they run within either a web browser or an applet viewer. JDK provides a standard applet viewer tool called applet viewer.
3. generally, execution of an applet does not begin at main() method.
4. Output of an applet window is not performed by System.out.println(). Rather it is handled with various AWT methods, such as drawString().