kentoh - Fotolia
When Java Runtime Environment was released in 1996, there were two ways to distribute applications. One was as a stand-alone application that would run like any other and could be installed on a Windows- or Linux-based workstation. The second was as a Java applet that would run inside of a web browser.
Therein lays the key difference between applets and applications in Java. Java applets operate within a web browser, while Java applications do not.
The term applet tends to cause some confusion when it describes a Java program that runs in a web browser. The word is commonly used in many different contexts throughout the technology world. For example, Microsoft's official documentation refers to individual programs, such as Device Manager and Power Options, as applets.
The word applet is often used interchangeably with the word widget or plugin. In general terms, any program that runs within another program -- or implements some type of subroutine within the confines of another application -- is often referred to as an applet. The greater program as a whole would be called the application.
With Java, you could think of the web browser as the application. The Java applet that runs within the web browser provides functionality that is dependent on the containing application. Hence, this is the main difference between an applet and an application in Java.
Modern browsers no longer support Java applets, and if you attempt to view one in a webpage, it will normally trigger an error message that says, "Your browser is completely ignoring the <APPLET> tag." However, it is possible to run Java applets via the AppletViewer tool packaged with older versions of the JDK.
This animated GIF shows a browser that refuses to render an applet, followed by the webpage running via the AppletViewer application and resulting in the tic-tac-toe application execution.
Differences between applet and application in Java
From a coding standpoint, there are several important differences between an applet and an application in Java:
|Deployment target||Web browser||Java Runtime Environment (JRE)|
|Default exceptions||Constructor throws HeadlessException||Throws no default exceptions|
|Packaging||Class file or JAR||Class file or JAR|
|Support||Discontinued with Java 9||Supported with no talk of discontinuation|
Java applet vs. application in code
The following image shows a simple Hello World application coded first as a Java applet and then as a Java application:
Discontinued applet support
In 2017, Oracle decided to remove the Java applet plugin from the JDK, and modern browsers like Chrome and Firefox will ignore any applets embedded within an HTML page.