The Java Applet Viewer

Applet viewer is a command line program to run Java applets. It is included in the SDK. It helps you to test an applet before you run it in a browser.



The Java Applet Viewer


Applet viewer is a command line program to run Java applets. It is included in the SDK. It helps you to test an applet before you run it in a browser. Before going any further, lets see what an applet is?

An applet is a special type of application that's included as a part of an HTML page and can be stored in a web page and run within a web browser. The applet's code gets transferred to the system and then the Java Virtual Machine (JVM) of the browser executes that code and displays the output.. So for running the applet,  the browser should be Java enabled. To create an applet, we need to define a class that inherits the Applet.

We generally use web browsers to run applets. Its not always mandatory to open a Web browser for running an applet. There is another way as well. The other way to run an applet is through Java applet viewer. This is a tool that acts as a test bed for Java applets. The working of Applet viewer is a bit different from a Web browser, though they are logically same. The Applet viewer runs on the HTML documentation, and uses embedded applet tags. The difference in using the applet viewer and the web browser to run the applet is that the applet viewer only deals with the applet code not the HTML cod i.e. it doesn't display HTML code. So we should test our program in applet viewer and web browser to confirm its working.

The applet viewer command connects to the documents or resources designated by urls. It displays each applet referenced by the documents in its own window.

The syntax for the applet viewer is:

appletviewer Options URL 

Where the URL specifies the location of the applet program and the Options argument specifies how to run the Java applet. We can use only one option -debug that starts the applet viewer in the Java debugger. Using this option we can debug an applet.

The following program shows how to build an applet and the HTML file for it. Firstly create a class. Then start the applet using init method. After that enter a string as str = "This is my first applet". Use paint method to give the dimensions of the applet. Beneath that is the HTML file which shows how to give the body for applet.

Here is the Java File:

import java.applet.*;
import java.awt.*;
public class Myapplet extends Applet{
	String str;
	public void init(){
		str = "This is my first applet";
	public void paint(Graphics g){
		g.drawString(str, 50,50);

Here is the HTML File:

<applet code="Myapplet",height="200" width="200">

After building the program, run the applet and the applet viewer as shown below.

C:\javac> javac

C:\javac>appletviewer Myapplet.html

When we run the applet viewer it will display the window as shown below.

Back to Java Introduction




We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

Share on Google+Share on Google+

The Java Applet Viewer

Posted on: February 26, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: The Java Applet Viewer   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
August 27, 2012
applets viewer are not loaded

i got the error as below C:\Program Files\Java\jdk1.7.0\bin>appletviewer java.lang.NullPointerException at be.init( at at
MD. Parvez Mosaraf
September 2, 2012

Thank you web Developer .
October 23, 2012

how to run applet program using applet viewer command.....?
March 8, 2013

what is syncronzation and explain withexample
March 8, 2013

February 28, 2014
Start : applet not initialized

E:\java>appletviewer AppletParameter.html java.lang.NumberFormatException: null at java.lang.Integer.parseInt( at java.lang.Integer.parseInt( at AppletParameter.init( at at
April 22, 2014
I am unable to launch applet viewer in VM.

Hi, I have JRE, but I am unable to launch the applet viewer in the VM. So can you please there any plugins is required or is there any polices is required or any other. This very high priority issue. Please help me. Thanks in advance.. Prasad
April 22, 2014
I am unable to launch applet viewer in VM.

Hi, I am working in VM, but I am unable to launch the applet viewer, even I have the JRE. Can you please suggest, how to approach to launch the applerviewer. This very high priority issue in my project...Please help me. Thanks in addvance. Prasad
September 9, 2013
warning in running applet program

Warning: Can't read AppletViewer properties file: C:\Users\DALIP\.hotjava\proper ties Using defaults.