How To Run a Java Applet using Command Prompt

To run a Java Applet using command prompt, we need to create a html file and link it to our applet.

To do so, follow these steps:

  1. Write your java applet code in a text editor and save it as (eg. for this program)
  2. Write the following html code in a text editor, replace the YourClassName.class with the name of your class and save it as YourClassName.html (eg. MyApplet.html for this program)

    Play around with the ‘width‘ and ‘height‘ attributes in the program to resize your applet.
  3. Make sure u save the applet file and the html file in the same folder.
  4. Then compile your applet in the command prompt (i.e. till ‘javac’) but don’t run it.
    If you don’t know how to do that then follow this post till step 7. Skip the steps that u know you have already done.
  5. Then type ‘appletviewer YourClassName.html’
  6. And Voila! Your applets running!

Now start practicing applets and let us know how it works for you :)

The following two tabs change content below.

Lalit Mali

Lalit is a technology enthusiast, a programming lover and currently an Android fan.

20 thoughts on “How To Run a Java Applet using Command Prompt

  1. Thank you so much…it is very helpful and easy.,by following your steps i got expected output for my applet program.. again thanks alot..

  2. yes it works…. but cant we run it directly from the browser..what are the steps and requuirements..
    thanks in advance

  3. Rahul either your JDK is faulty or your path is set incorrectly. Refer this post to fix your problem:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">