0
import java.awt.*;
import java.applet.*;

/* <applet code="Demonstration_21" width=300 height=300> </applet> */
public class Demonstration_21 extends Applet{

    public void paint(Graphics g){
    g.drawString("Welcome",150,150);
    }
}

I have written this code to run an applet program but whenever I compile it gives some warning as:

  1. Demonstration_21.java uses or overrides a deprecated API
  2. Recompile with Xlint:deprecation for details.

And whenever I run this code it gives error as:

Demonstration_21 has been compiled by a more recent version of Java
Runtime(class file version 55.0),this version of Java Runtime only 
recognizes class file versions up to 52.0

My appletviewer is not initialized.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Viren
  • 9
  • 2
  • 2
    Java Applet is deprecated in Java 9. Unless you are forced to use it for school work or so, better to not waste your time. – iTech Feb 03 '19 at 03:27
  • @iTech *"Unless you are forced to use it for school work.."* And if that is the case, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). That was written even **before** applets & JWS were deprecated. – Andrew Thompson Feb 03 '19 at 06:09

2 Answers2

0

You should build it with Java 8 instead of Java 11.

Here is a list of class file versions an the related Java major versions List of Java class file format major version numbers?

Dan_Maff
  • 311
  • 2
  • 7
-1

you miss something..

In applet tag code attribute you have to specify .class file.

import java.awt.*;
import java.applet.*;

/* <applet code="Demonstration_21.class" width=300 height=300> </applet> */
public class Demonstration_21 extends Applet{

    public void paint(Graphics g){
    g.drawString("Welcome",150,150);
    }
}
  • *"you have to specify .class file"* No, you *don't*. The proper form of the `code` parameter is the fully qualified class name, not the file name and not the path + file name. I've yet to encounter a browser that would *fail* to load an applet due to adding `.class`, but it is both unnecessary & incorrect. – Andrew Thompson Feb 03 '19 at 06:12
  • You don't have to specify the .class file, you just have to compile your project using the JDK 8 because if you use JDK 9+ it won't compile because it has been deprecated on those JDK's. – Yonela Nuba May 15 '22 at 21:10