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 YourClassName.java (eg.  MyAppet.java 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 ClassName.java’) 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.
  • asha

    hey thanx dear……..

  • kameswari

    Thanks a lot sir/madam. Its is very clear and helpful.

  • abi

    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..

  • meghana

    Thank you so much…

  • sonali

    thank u so much…..

  • xaloon

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

  • Ranjeet

    Respected Sir/Madam
    very very thanks!!!!!!!!!!!!!!!

  • karan

    thank you sir….its working
    thank you so much

  • Rahul

    error javac recognising as internal or erternal command….

  • doak

    Rahul either your JDK is faulty or your path is set incorrectly. Refer this post to fix your problem:
    http://www.mycoding.net/2011/02/218/

  • Moa Long’s

    Thanks a ton…its working…yipee!

  • Goutan

    Thanks a lot…………,greatest teaching………..

  • iranna

    thanx dear

  • nivetha

    thank you very much it is very useful for me at a right time

  • nivetha

    thank you very much it,s work out.it is very useful for me at a right time

  • Uva

    run my first applet.. thank you..

  • sarita

    thanks

  • Roshy

    Thank you

  • sandy

    like this

  • umerali

    thank sir/mam it looks like very easy but it is not thank you very much