What is the difference between Java Applet and HTML?
Here's an explanation of the difference between executing an applet with appletviewer and through an HTML file:
Java Applet: Applets are small Internet-based program written in Java, a programming language for the web, which can be downloaded by any computer.
The applet is also able to run in an HTML file that the Applet is embedded within, provided that the browser running the HTML file has a Java Virtual Machine (JVM).
appletviewer: This is a command line tool from the JDK (Java Development Kit) that allows you to run applets outside of a web browser. When you run an applet using the
appletviewertool, it does not need to be embedded within an HTML file; instead, it can be launched directly.HTML file: On the other hand, applets can also be embedded within HTML files. To run the applet, you would open the HTML file in a web browser that has a JVM. The browser reads the HTML file, comes across the applet tag (which has been deprecated in HTML5, by the way, and replaced by the object tag), and runs the applet within the web page.
There are some key differences in executing an applet with appletviewer versus through an HTML file in a web browser:
Compatibility and Convenience: HTML file approach will work on any browser with a JVM, so it's more compatible and convenient for end users.
Security Restrictions: Applets run in a browser have stricter security restrictions, because they run within a sandbox to prevent unauthorized activities. For example, an applet cannot access local file system of the viewer's computer unless granted permission. However, with
appletviewer, these restrictions may not be as stringent.Deprecation: As of 2021, many modern web browsers do not support applets at all due to security reasons and because the technology has been deprecated.
appletvieweris typically used now only for testing during development, rather than for actual deployment of applets.
Note: With Java 9, the appletviewer command is deprecated and may not be included in future JDK.
Oracle, the maintainers of Java, have planned to remove the Applet API in the future due to the move away from applets in modern web development.