Q.
Write the difference between applet and applications’
Difference Between Applet and Application in Java
1. Definition:
An applet is a small Java program designed to be embedded and run inside a web browser or
applet viewer. It typically interacts with a web page and is executed as part of a browser
session.
A Java application is a stand-alone program that runs directly on a system’s Java Runtime
Environment (JRE) without the need for a browser. It can be a command-line program or a
graphical user interface (GUI) application.
2. Execution Environment:
Applets are executed within a web browser or applet viewer, and their execution depends on the
presence of the Java plugin in the browser.
Applications, on the other hand, run directly on a user’s machine. They do not require a
browser, and they are executed independently by invoking the main() method from the
command line or a graphical launcher.
3. Entry Point:
An applet does not have a main() method. Instead, it has an init() method which is called when
the applet is loaded, along with other lifecycle methods like start(), stop(), and destroy().
A Java application uses the **main()** method as the entry point of the program. The execution
of the application starts from this method.
4. User Interface:
Applets are typically used to create small graphical user interfaces (GUIs) embedded in a web
page. They often use the Graphics class for rendering visual content.
Applications, especially those with GUI (Graphical User Interface), can be developed using Java
Swing or AWT. These programs may have more complex and independent interfaces and are
usually not embedded in web pages.
5. Deployment:
Applets are deployed as part of a web page. To run, the user needs a browser that supports
Java (with the Java plugin). The applet is executed when the browser loads the webpage
containing the applet code.
Applications are typically standalone programs. They are deployed and run directly on the user's
machine without requiring a browser. The user typically runs the application by double-clicking
an executable file or running a script.
6. Security:
Applets run inside the browser's sandbox, a restricted environment that limits their ability to
interact with the host system. This is to protect the system from potential security threats from
untrusted applet code.
Applications run directly on the user's machine and do not have the same sandbox restrictions
as applets. However, they can still be subject to security policies enforced by the operating
system or the JVM.
Conclusion:
In summary, applets are small programs embedded in web pages and executed within a
browser, while applications are independent programs that run directly on a system without
requiring a browser. The rise of more modern web technologies has led to a decrease in the use
of applets, whereas Java applications continue to be used for a wide variety of software
development.