Java applet

From Free net encyclopedia

A Java applet is an applet delivered in the form of Java bytecode. Java applets can run in a Web browser using a Java virtual machine (JVM), or in Sun's AppletViewer, a stand alone tool to test applets. Java applets were introduced in the first version of the Java language in 1995. Java applets are usually written in the Java programming language but they can also be written in other languages that compile to Java bytecode such as Jython.

Applets are used to provide interactive features to web applications that cannot be provided by HTML. They are executed in a sandbox by most web browsers, preventing them from accessing local data. The code of the applet is downloaded from a web server and the browser either embeds the applet into a web page or opens a new window showing the applet's user interface. The applet can be displayed on the web page by making use of the deprecated APPLET HTML element [1], or the recommended OBJECT element [2]. This specifies the applet's source and the applet's location statistics. The applet's location cannot be controlled by Cascading Style Sheets.

Since Java's bytecode is platform independent, Java applets can be executed by browsers for many platforms, including Windows, Unix, Mac OS and Linux.There are open source tools like applet2app which can be used to convert an applet to a stand alone Java application/windows executable. This has the advantage of running a Java applet in offline mode without the need for internet browser software.

A Java Servlet is sometimes informally compared to be "like" a server-side applet, but it is different in its language, functions, and in each of the characteristics described here about applets.

Contents

Technical information

A Java applet extends the class Template:Javadoc:SE, or in the case of a Swing applet, Template:Javadoc:SE. The class must override methods from the applet class to set up a user interface inside itself (Applet is a descendant of Template:Javadoc:SE which is a descendant of Template:Javadoc:SE).

Compatibility issues

Sun has made a considerable effort to ensure compatibility is maintained between Java versions as they evolve. For example, Microsoft's Internet Explorer, the most popular web browser since late 1990s, used to ship with Microsoft's own JVM as the default. The MSJVM had some extra non-Java features added which, if used, would prevent MSJVM applets from running on Sun's Java (but not the other way round). Sun sued for breach of trademark, as the point of Java was that there should be no proprietary extensions and that code should work everywhere. Development of MSJVM was frozen by a legal settlement, leaving many users with an extremely outdated Java virtual machine. Later, in October 2001, MS stopped including Java with Windows, and for some years it has been left to the computer manufacturers to ship Java independently of the OS. Most new machines now ship with official Sun Java.

Some browsers (notably Firefox) do not do a good job of handling height=100% on applets which makes it difficult to make an applet fill most of the browser window (Javascript can be used for this but its hard to get it perfect). Having the applet create its own main window is not a good solution either, as this leads to a large chance of the applet getting terminated unintentionally and leaves the browser window as a largely useless extra window.

Advantages of applets

A Java applet can have any or all of the following advantages:

  • it is simple to make it work on Windows, Mac OS and Linux, i.e. to make it cross platform
  • the same applet can work on "all" installed versions of Java at the same time, rather than just the latest plug-in version only
  • it can work without any security approval from the user - who doesn't need to trust the software's author
  • it is supported by most web browsers
  • it will cache in most web browsers, so will be quick to load when returning to a web page
  • it can have full access to the machine it is running on if the user agrees
  • it can improve with use: after a first applet is run, the JVM is already running and starts quickly, benefitting regular users of Java
  • it can run at a comparable (but generally slower) speed to other compiled languages such as [[C++]]
  • it can be a real time application
  • it can move the work from the server to the client, making a web solution more scalable with the number of users/clients

Disadvantages of applets

A Java applet is open to any of the following disadvantages:

  • it requires the Java plug-in, which isn't available by default on all web browsers
  • it can't start up until the JVM is running, and this may have significant startup time the first time it is used
  • if it is uncached, it must be downloaded (usually over the internet), and this takes time
  • it is considered more difficult to build and design a good user interface with applets than with HTML-based technologies
  • if untrusted, it has severely limited access to the user's system - in particular having no direct access to the client's disc or clipboard

Though not strictly a disadvantage of Java applets, alternative technologies exist (for example, Ajax and Flash) that satisfy much of the scope of what is possible with an applet.

Another alternative to applets for client side Java is Java Web Start, which runs outside the browser. In addition to the features available to applets, a simple permissions box can give Java Web Start programs read and/or write access to specified files stored on the client, and to the client's clipboard.

See also

External links

es:Java applet it:Java applet ja:Javaアプレット nl:Java-applet