Applets Vs Applications Java

Applets Vs Applications Java


All Java programs can be classified as Applications and Applets. The striking differences are that applications contain main() method where as applets do not. One more is, applications can be executed at DOS prompt and applets in a browser. We can say, an applet is an Internet application. Come on, read further Applets Vs Applications.

Definition – Importance

Applet is a Java program executed by a browser. The position of applets in software world is they occupy the client-side position in Web communication. On the server-side, you guess, another Java program comes, Servlets. Applets on client-side and servlets on server-side makes Java a truly "Internet-based language". To execute applets, the browsers come with JRE (Java Runtime Environment). The browsers with Java Runtime Environment (or to say, JVM) loaded are known as Java enabled browsers.

Note: Browser do not have a Java compiler as a compiled applet file (.class file) is given to browser to execute.

Applications Vs. Applets

You have seen two main differences between applications and applets. Let us summarize them.

Feature Application Applet
main() method Present Not present
Execution Requires JRE Requires a browser like Chrome
Nature Called as stand-alone application as application can be executed from command prompt Requires some third party tool help like a browser to execute
Restrictions Can access any data or software available on the system cannot access any thing on the system except browser’s services
Security Does not require any security Requires highest security for the system as they are untrusted

Advantages of Applets of Applets Vs Applications

  1. Execution of applets is easy in a Web browser and does not require any installation or deployment procedure in realtime programming (where as servlets require).
  2. Writing and displaying (just opening in a browser) graphics and animations is easier than applications.
  3. In GUI development, constructor, size of frame, window closing code etc. are not required (but are required in applications).

Restrictions of Applets of Applets Vs Applications

  1. Applets are required separate compilation before opening in a browser.
  2. In realtime environment, the bytecode of applet is to be downloaded from the server to the client machine.
  3. Applets are treated as untrusted (as they were developed by unknown people and placed on unknown servers whose trustworthiness is not guaranteed) and for this reason they are not allowed, as a security measure, to access any system resources like file system etc. available on the client system.
  4. Extra Code is required to communicate between applets using AppletContext.

What Applet can't do – Security Limitations of Applets Vs Applications

Applets are treated as untrusted because they are developed by somebody and placed on some unknown Web server. When downloaded, they may harm the system resources or steal passwords and valuable information available on the system. As applets are untrusted, the browsers come with many security restrictions. Security policies are browser dependent. Browser does not allow the applet to access any of the system resources (applet is permitted to use browser resources, infact, applet execution goes within the browser only).

  • Applets are not permitted to use any system resources like file system as they are untrusted and can inject virus into the system.
  • Applets cannot read from or write to hard disk files.
  • Applet methods cannot be native.
  • Applets should not attempt to create socket connections
  • Applets cannot read system properties
  • Applets cannot use any software available on the system (except browser execution area)
  • Cannot create objects of applications available on the system by composition

The JRE throws SecurityException if the applet violates the browser restrictions.

Applet Architecture

Applets permit GUI and handling events. Infact, an applet will be in waiting mode forever expecting some event (input) to occur from the user. Applets are event driven and window-based. The event is forwarded by the AWT GUI environment (graphics environment) to the applet. The applet takes the event, do some action and return the control back to AWT. Applet does not keep the execution control with it for a long time. If the programmer would like to listen the music continuously or use some banner to display, he must create a separated thread and assign the job to it.

Note: Do not try to take input from keyboard with applets as applets are window-based and instead you can create some GUI text field and take input.

5 thoughts on “Applets Vs Applications Java

Leave a Reply

Your email address will not be published. Required fields are marked *