Java Applet Basics Tutorial

Java applets are developed in Java language.

In Java, an applet is a program that runs in a Web browser. An applet can be a fully functional Java application because it has full Java API at its disposal.

A Java applet is a small Java program that runs inside another program such as web browser. Both Internet Explorer and Netscape navigator can run Java applet. Java applets are embedded into web pages to rotate images for animations and to access database on the internet.

Java Applet Example

The following is a simple applet named

/* Java Program Example - Java Applet Basics */
import java.applet.*;
import java.awt.*;

public class HelloWorldApplet extends Applet
   public void paint (Graphics g)
      g.drawString ("Hello World", 25, 50);

Compile and Execute Java Applet Program

This is for BlueJ user. To compile and execute an applet program/application, follow these steps:

  • First copy and paste the above code into your BlueJ compiler having class name as HelloWorldApplet
  • Now compile the program
  • After successful compilation, just close the source code window
  • Now make right click on the HelloWorldApplet
  • And then click on Run Applet
  • A new window will come out asking for the configuration like window width, height etc. Here is the figure.
java applet

Now provide 200 in height box, and 400 in width box and now click on OK button, and watch the output as shown here.

Here is the output window of the above applet program of 400 width and 200 height.

java applet tutorial

Here are the two import statements in Java, that brings the classes into the scope of our applet class in Java:

  • java.awt.Graphics.
  • java.applet.Applet.

Java Online Test

« Previous Tutorial Next Tutorial »

Follow/Like Us on Facebook

Subscribe Us on YouTube