Share on Google+Share on Google+

Java - Applet Hello World

This example introduces you with the Applet in Java. You will learn how to develop applet code and run in the browser.

Java - Applet Hello World


This example introduces you with the Applet in Java. You will learn how to develop applet code and run in the browser.

Applet is a program provided by java which is designed for execution within the web browser. Applets are mostly used for a small internet and intranet applications because of small size and it's compatibility among almost all web browsers. Applets are also very secure.  For example, Applets can be used to serve animated graphics on the web.

This example creates a simple applet that displays Hello World message.

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

public class HelloWorldApplet extends Applet{
  public static void main(String[] args){
  Frame frame = new Frame("");
  Applet app = new HelloWorldApplet();
  frame.addWindowListener(new WindowAdapter(){
 public void windowClosing(WindowEvent e){
 public void paint(Graphics g){
  g.drawString("Hello World!",200,100);

Compiling Applets:


Running Applet from console:

java HelloWorldApplet

Running Applet from Web browser:

Running applet in browser is very easy job, create an html file with the following code:

<title>A Simple Applet program</title>
HelloWorldApplet.class" WIDTH=700 HEIGHT=500>

The Applet tag in html is used to embed an applet in the web page. 

<APPLET CODE="HelloWorldApplet.class" WIDTH=700 HEIGHT=500>

CODE tag is used to specify the name of Java applet class name. To test your applet open the html file in web browser. You browser should display applet. You can also try this applet online by clicking on the following link.

Try the example online

Download Applet Example


Posted on: June 4, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Java - Applet Hello World   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
July 2, 2011
advance java

give better programs
March 12, 2013

Abdulhan O. Salapuddin
February 3, 2012
Java Applet

this is not a comment. This is a question,how to declare a file name
December 13, 2012

i am not able to run applet program in my web browser what is the plugin i shud use for it i have changed the internet settings and enabled applet scripting please help me
May 4, 2013
Permission Denied

I am not able to run my html file on browser. It asks for permission. How to set permission for it in windows 7??
August 14, 2013

santha kumar
September 10, 2013
java is most intersting programming language

i want learn real examples in java