Site icon TestingDocs.com

Java Applets are deprecated

Overview

In the olden days, applets are the way to embed java code into web browsers. Java applets are deprecated since Java 9. However, in these modern days, we have efficient alternatives for Java Applets.

Java applets are special Java programs that were developed to run embedded Java code in Web pages. An applet is launched from the web document HTML code. To develop an applet we need to extend the Applet class. 

 

Java Listing

package applets;

import java.applet.Applet;
import java.awt.Graphics;

@SuppressWarnings("deprecation")
public class HelloApplet extends Applet {

  public void paint(Graphics g) {
    g.drawString("Hello from www.TestingDocs.com", 25, 25);
  }
}

Try the run the applet Right click >> Run As >> Java Applet .

We would get the following error.

Error

Error: Could not find or load main class sun.applet.AppletViewer
Caused by: java.lang.ClassNotFoundException: sun.applet.AppletViewer

Screenshot:

 

An AppletViewer is a java program that executes java applets that are embedded in web pages.

Java Applet Alternatives

Since, Java Applets are deprecated we will look at some alternatives to run Java code in a web browser.

Java Web Start is a good alternative for java applets.

https://docs.oracle.com/javase/tutorial/deployment/webstart/

Server socket programming etc. Other Web Technologies, for example HTML 5 is a good alternative to Java Applets.

For Enterprise needs Servlets/JSP and EJBs are way more powerful way to run dynamic Java code on Web Containers like Tomcat, JBoss, WebLogic etc.  

Java Tutorial on this website: https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/in/java/

Exit mobile version