You are on page 1of 8

Java Applets

A Java applet is a small application that is written in the Java programming language, or another
programming language that compiles to Java bytecode, and delivered to users in the form of Java
bytecode. The user launches the Java applet from a web page, and the applet is then executed
within a Java virtual machine (JVM) in a process separate from the web browser itself. A Java
applet can appear in a frame of the web page, a new application window, Sun's AppletViewer, or a
stand-alone tool for testing applets. Java applets were introduced in the first version of the Java
language, which was released in 1995.

Java applets are usually written in Java, but other languages such as Jython, JRuby, Pascal,
Scala, or Eiffel (via SmartEiffel) may be used as well.

Java applets run at very fast speeds and, until 2011, they were many times faster than JavaScript.
Unlike JavaScript, Java applets had access to 3D hardware acceleration, making them well-suited
for non-trivial, computation-intensive visualizations. As browsers have gained support for
hardware-accelerated graphics thanks to the canvas technology (or specifically WebGL in the case
of 3D graphics), as well as just-in-time compiled JavaScript, the speed difference has become less

Since Java bytecode is cross-platform (or platform independent), Java applets can be executed by
browsers (or other clients) for many platforms, including Microsoft Windows, FreeBSD, Unix,
macOS and Linux.

Java applet technology has been marked for deprecation

The Applets are used to provide interactive features to web applications that cannot be provided by
HTML alone. They can capture mouse input and also have controls like buttons or check boxes. In
response to user actions, an applet can change the provided graphic content. This makes applets
well-suited for demonstration, visualization, and teaching. There are online applet collections for
studying various subjects, from physics to heart physiology.

An applet can also be a text area only; providing, for instance, a cross-platform command-line
interface to some remote system. If needed, an applet can leave the dedicated area and run as a
separate window. However, applets have very little control over web page content outside the
applet's dedicated area, so they are less useful for improving the site appearance in general,
unlike other types of browser extensions (while applets like news tickers or WYSIWYG editors are
also known). Applets can also play media in formats that are not natively supported by the

Impetus IT Services Pvt.Ltd.
B-16, First floor, Sant Tukaram Vyapar Sankul, Sector - 24, Nigdi, Pune, Maharashtra. India. Pin – 411044.
Mobile 9970600774, 9730012775|Board 91-20-27640406|Fax 91-20-27641703
Email : | Website

Sant Tukaram Vyapar Sankul. As applet inherits from container. B-16. A Java Servlet is sometimes informally compared to be "like" a server-side applet. However. Pin – 411044. As applets were available before CSS and DHTML were standard. which then runs in a separate window (not inside the invoking browser). Java system libraries and runtimes are backwards-compatible. Sector .24. functions.Ltd. the same applet may have a different appearance depending on the parameters that were passed. this usage is now declining. This domain can be different from the domain where the surrounding HTML document is hosted. The class which must override methods from the applet class to set up a user interface inside itself (Applet) is a descendant of Panel which is a descendant of Container. or in the case of a Swing applet.JApplet. Java Web Start allows the launching of unmodified applet code. Heavily criticized. Embedding into a web page Impetus IT Services Pvt. Maharashtra. so applets got a reputation as slow-loading components. 9730012775|Board 91-20-27640406|Fax 91-20-27641703 Email : hrishikesh@impetusitservices. javax. there are often many of them. Because of this. they were also widely used for trivial effects such as rollover navigation buttons. including regions with user specific visualization. Nigdi. since . A Java applet extends the class java. India. and in each of the characteristics described here about applets. preventing them from accessing local data like the clipboard or file | Website http://impetusits. The domain from where the applet executable has been downloaded is the only domain to which the usual (unsigned) applet can communicate. an applet is usually delivered as a single file that has a size like an image file (hundreds of kilobytes to several megabytes). blogs and magazines are recommending that the Java Web Start technology be used in place of applets.swing. While classes are small files. First . Technical information Java applets are executed in a sandbox by most web browsers. The code of the applet is downloaded from a web server. but it is different in its language.jars were introduced.browser.applet.Applet. allowing one to write code that runs both on current and on future versions of the Java virtual machine. Mobile 9970600774. Pune. Pages coded in HTML may embed parameters within them that are passed to the applet. after which the browser either embeds the applet into a web page or opens a new window showing the applet's user interface. Similar technologies Many Java developers. The first implementations involved downloading an applet class by class. it has largely the same user interface possibilities as an ordinary Java application.

Sant Tukaram Vyapar Sankul. // This should be saved in a file named as "HelloWorld. y = 10). world!" example. Tags also specify the message that shows up in place of the applet if the browser cannot run it due to any reason. the support of the object tag was not yet consistent among browsers and Sun kept recommending the older applet tag for deploying in multibrowser environments. 360).*". In January 2016. the object tag currently requires JavaScript (that recognizes the browser and adjusts the tag). import java. This specifies the applet's source and location. First floor. 30. Nigdi. world!" as output. or the recommended object element.applet. Both object and embed tags can also download and install Java virtual machine (if required) or at least lead to the plugin page.Ltd. 20. However.drawString("Hello. Oracle announced that Java runtime environments based on JDK 9 will discontinue the browser plug-in. To support multiple browsers. Mobile 9970600774. 10).The applet can be displayed on the web page by making use of the deprecated applet HTML element. y = 30). world!". Pune. import java. India. The Java browser plug-in relies on NPAPI.*. Pin – 411044. 20. g. Sector . usage of additional browser-specific tags or delivering adapted output from the server side. The example also uses classes from the Java Abstract Window Toolkit (AWT) to produce the message "Hello. despite object being officially a recommended tag. 9730012775|Board 91-20-27640406|Fax 91-20-27641703 Email : hrishikesh@impetusitservices.drawArc( . applet and object tags also support loading of the serialized applets that start in some (rather than initial) state. Deprecating applet tag has been criticized. B-16. as of 2010. Impetus IT Services Pvt. The embed element can be used[29] with Mozilla family browsers (embed was deprecated in HTML 4 but is included in HTML 5).com | Website http://impetusits. // Applet code for the "Hello. Maharashtra. as it remained the only tag consistently supported by the most popular browsers. g.applet package. Example The following example illustrates the use of Java applets through the java. 20. // Draws a circle on the screen (x = 40. public class HelloWorld extends Applet { public void paint (Graphics g) { // Print a message on the screen (x = 20. 0. which many web browser vendors are deprecating due to its age and security issues. Oracle now provides a maintained JavaScript code to launch applets with cross platform workarounds.24.

} } Simple applets are shared freely on the Internet for customizing applications that support | Website http://impetusits.drawRect(100. // Draws a square on the screen (x1 = 100. 300.drawRect(100. y1 = 100.class runs. Sector . For example: <!DOCTYPE html> <html> <head> <title>HelloWorld_example. y2 = 300). 100. B-16.jar. x2 = 300. India. Sant Tukaram Vyapar Sankul. x2 = 200.class" height="40" width="200"> This is where HelloWorld. Pin – 411044.24. Mobile 9970600774.Ltd.html</title> </head> <body> <h1>A Java applet example</h1> <p> Here it is: <applet code="HelloWorld. Pune. g. </applet> </p> </body> </html> When the page is accessed it will read as follows: A Java applet example Here it is: Hello.// Draws a rectangle on the screen (x1 = 100. 9730012775|Board 91-20-27640406|Fax 91-20-27641703 Email : hrishikesh@impetusitservices. Nigdi. After . 200. 200). y2 = 200). g. the resulting . 300). world! To minimize download time. if all necessary classes are placed in the compressed archive example. 100. Maharashtra.class file can be placed on a web server and invoked within an HTML page by using an <applet> or an <object> tag. applets can be delivered in the form of a jar file. y1 = 100. the following embedding code could be used instead: Impetus IT Services Pvt. In the case of this example. First floor.

Sant Tukaram Vyapar Sankul.class runs.Ltd. Microsoft Windows and macOS – that is.5 and greater stop the JVM and restart it when the browser navigates from one HTML page containing an applet to another containing an applet. It should be noted that JRE versions 1. Pin – 411044. However. Applets are supported by most web browsers. Mobile 9970600774. such as figure positions on the . Maharashtra. India. In contrast.<p> Here it is: <applet archive="example. The applet naturally supports the changing user state. First floor. B-16. a properly configured browser loads (and caches) the latest applet version.jar" code="HelloWorld" height="40" width="200"> This is where HelloWorld. Impetus IT Services Pvt. so there is no need to support legacy versions. Pune. </applet> </p> Advantages A Java applet can have any or all of the following advantages: It is simple to make it work on FreeBSD. Most web browsers cache applets so they will be quick to load when returning to a web page. Linux. the JVM is already running and starts quickly (the JVM will need to restart each time the browser starts afresh). Applets also improve with use: after a first applet is run. The same applet can work on "all" installed versions of Java at the same time. making a web solution more scalable with the number of users/clients. It can move the work from the server to the client. thus allowing for development in their favorite Java SE development environment. rather than just the latest plug-in version only. to make it cross | Website http://impetusits. if an applet requires a later version of the Java Runtime Environment (JRE) the client will be forced to wait during the large download. All one must do after that is re- test the applet in the AppletViewer program or a web browser to ensure it conforms to security restrictions. 9730012775|Board 91-20-27640406|Fax 91-20-27641703 Email : hrishikesh@impetusitservices. that server normally needs to support all prior versions for users which have not kept their client software updated. Sector . If a standalone program (like Google Earth) talks to a web server.24. Nigdi. Developers can develop and debug an applet directly simply by creating a main routine (either in the applet's class or in a separate class) and calling init() and start() on the applet.

the user running it the first time will need to wait for the large JRE download to complete. As a result.  Unlike the older applet tag. India. Maharashtra.policy file in the JAVA JRE installation.  Most browsers. Further starting with Java 7 Update 51 unsigned applets are blocked by default. Java applets are fast—and can even have similar performance to native installed software. applets can harm the accessibility of a web site to users with special needs. 9730012775|Board 91-20-27640406|Fax 91-20-27641703 Email : hrishikesh@impetusitservices. or a specific JRE. Disadvantages A Java applet may have any of the following disadvantages compared to other client-side web technologies:  Java applets depend on a Java Runtime Environment (JRE). First floor. Pune.An untrusted applet has no access to the local machine and can only access the server it came from. Security There are two applet types with very different security models: signed applets and unsigned applets. Some organizations only allow software installed by an administrator. It also normally requires a plug-in for the web browser. As of Java SE 7 Update 21 (April 2013) applets and Web-Start Apps are encouraged to be signed with a trusted certificate. Mobile 9970600774. do not run Java applets at all. or to other network sources other than the network source that served the applet to the browser. the object tag needs workarounds to write a cross-browser HTML document.  As with any client-side | Website http://impetusits. one can grant access to the local filesystem or system clipboard for example. Sector .  If an applet requires a newer JRE than available on the system. Therefore. Sant Tukaram Vyapar Sankul. some users can only view applets that are important enough to justify contacting the administrator to request installation of the JRE and plug-in. a signed applet can have full access to the machine it is running on if the user agrees. which is a reasonably complex and heavy-weight software package. simply editing the java . Pin – 411044. notably mobile browsers on iOS or Android. Nigdi.Ltd. they can be run by creating an exception in the Java Control Panel.  Unsigned Impetus IT Services Pvt. security restrictions may make it difficult or even impossible for an untrusted applet to achieve the desired goals.24. B-16. However. This makes such an applet much safer to run than a standalone executable that it could . and warning messages appear when running unsigned applets.  There is no standard to make the content of applets available to screen readers. However.

Nigdi. but these are classified as nuisances and not as true security flaws. B-16. indicating that this is an untrusted applet. Some studies mention applets crashing the browser or overusing CPU resources. many security problems have been discovered and fixed since Java was first released. Some of these (like the Calendar serialization security bug) persisted for many years with nobody being aware. they have no access to the local filesystem and web access limited to the applet download site. call native code.Ltd. India. there are also many other important restrictions. making this unreasonable. There were attempts to use applets for spreading Phoenix and Siberia exploits this way. Maharashtra. Sector . An unsigned applet can also be more dangerous to run directly on the server where it is hosted because while code base allows it to talk with the server. Others have been discovered in use by malware in the wild. use their own class loader. The rationale is that the author of the applet is now known Impetus IT Services Pvt. becoming equivalent to an ordinary standalone program. While they can run in a standalone frame. Mobile 9970600774. execute external commands on a local system or redefine classes belonging to core packages included as part of a Java release.  Signed A signed applet contains a signature that the browser should verify through a remotely running. and the user of the current machine also approves. As with any complex system. but usually people who manage the web site also manage the applet. For instance. such frame contains a header. it could only store such file into a temporary folder (as it is transient data) and has no means to complete the attack by executing it. | Website http://impetusits. Pune. Sant Tukaram Vyapar Sankul. but these exploits do not use Java internally and were also distributed in several other ways. running inside it can bypass the firewall. Successful initial call of the forbidden method does not automatically create a security hole as an access controller checks the entire stack of the calling code to be sure the call is not coming from an improper location. independent certificate authority server. Producing this signature involves specialized tools and interaction with the authority server maintainers. unsigned applets may be involved in combined attacks that exploit a combination of multiple severe configuration errors in other parts of the system. Pin – 411044. First floor. However. a signed applet can get more rights. The unsigned applet can also try to download malware hosted on originating server. 9730012775|Board 91-20-27640406|Fax 91-20-27641703 Email : . An applet may also try DoS attacks on the server where it is hosted.24. Limits on unsigned applets are understood as "draconian". Communities may solve this problem via source code review or running applets on a dedicated domain. Once the signature is verified. they cannot access all system properties.

JavaScript can coexist with applets in the same page. The related concerns include a non-responsive authority server. assist in launching applets (for instance. as the function and safety of the applet is guaranteed only by the developer itself. Maharashtra. deciding whom he or she trusts.  Self-signed Self-signed applets. 9730012775|Board 91-20-27640406|Fax 91-20-27641703 Email : | Website http://impetusits. Mobile 9970600774. and will be responsible for any deliberate damage. developers who wish to deploy Java applets have no alternative but to acquire trusted certificates from commercial sources. Java security problems are not fundamentally different from similar problems of any client-side scripting platform. may potentially pose a security risk. However. This approach allows applets to be used for many tasks that are otherwise not possible by client-side scripting. Sant Tukaram Vyapar Sankul. Pune. Nigdi. but most applet developers will seek third-party signing to ensure that users trust the applet's safety. this approach requires more responsibility from the user. and known applet publishers still doing something that the user would not approve of.Ltd. Alternatives Alternative technologies exist (for example. JavaFX is an extension of the Java platform and may also be viewed as an alternative. and has not been independently confirmed. Such self-signed certificates are usually only used during development prior to release where third-party confirmation of security is unimportant. All issues related to signed applets also apply to Microsoft ActiveX components. JavaScript is not always viewed as a competing replacement. JavaScript) that satisfy all or more of the scope of what is possible with an applet.24. Pin – 411044. in a separate frame or providing platform workarounds) and later be called from the applet code. which are applets signed by the developer themselves. java plugins provide a warning when requesting authorization for a self- signed applet. . wrong evaluation of the signer identity when issuing certificates. B-16. First floor. self-signed and unsigned applets are no longer accepted by the commonly available Java plugins or Java Web Start. Consequently. Hence signed applets that appeared from Java 1.1 may have more security concerns. As of 2014. Sector . Of these. Impetus IT Services Pvt.