Java Applets

Table of contents:

Java technology has invaded nearly every aspect of Web development. JavaScript and Java applets are used to make the client dynamic. JavaServer Pages and servlets are used on the server. JavaBeans, small reusable components that can be used to build larger Java programs and applets, have brought Java into the component world. The Java revolution has even extended into the application server arena, with Enterprise JavaBeans (EJB)transactional objectsand Java Database Connectivity (JDBC). A full discussion of Java technologies is, of course, beyond the scope of this book, indeed any book; a complete discussion would take a library of books! What is provided in this section is an overview of Java applets and some of its interesting architectural elements as related to making clients dynamic.

Using JavaScript in an HTML page is a simple way to make the client dynamic, but it does have limitations. In addition to JavaScript compatibility problems, the use of scripts in Web pages can work only with the tools and information available in the page. Additionally, as the code becomes complex, the nice JavaScript features that make it easy to use and deploy become a problem. It is not difficult to have JavaScript code evolve into spaghetti code. This is where Java comes in.

Java is much better suited to solving the large problems that scripting is not suitable for. In addition to being able to access the DOM, Java has the ability to define its own user interface, something even JavaScript can't do. Being a true object-oriented language, Java defines classes and uses inheritance. Perhaps the most important feature of Java, though, is that it is platform neutral. This is particularly important to Web application developers, because Web applications often exist in heterogeneous environments. The Java enthusiast's mantra is "write once; run everywhere."

The use of Java on the client is usually in the form of an applet. An applet is more or less a user interface control that is placed in a Web page. An applet is made up of both system and custom classes. A custom applet extends, or inherits, from the Java applet class. Additional user interface capabilities are available with the Abstract Windowing Toolkit (AWT), a Java class library that contains most of the user interface primitives and tools. More advanced user interface functions can be obtained from the Java Foundation Classes (JFC) and Swing components.[7]

[7] In addition to basic user interface tools, 3-D user interface libraries and specifications are available for the Java platform.

Because applets are referenced by a Web page, they need to be identified by a tag. The tag is used to identify an applet and, most important, where it can be obtained.[8] In addition to being platform neutral, Java applets are a good fit for the Web because deployment of applets is almost automatic. An tag's parameters define the type of object (Java), the name of the class file to load and run, and, optionally, the location, or URL, where the file or files can be found on the network. In the following HTML example, an applet called Bubbles is displayed to the user. The text between the begin and end tags is displayed in place of the applet for non-Java-enabled browsers.

[8] Previous versions of HTML had a separate tag. This tag, however, has been deprecated, and the more general tag is recommended instead.

Java applet that draws animated bubbles.

In this example, the codetype parameter indicates that the object is a Java applet. The classid parameter identifies the class name of the appletthe object that inherited the applet interface. The codebase parameter indicates that the Java applet class file can be obtained from the server www.wae-uml.org in the javaclasses directory and with HTTP. This means that the browser can get the applet by making another GET request to the Web server www.wae-uml.org.

Parameters can be supplied to an applet within the context of the tag. Separate tags can be placed between the begin and end tags. The browser allows the applet to access these parameters. In the following example, two parameters are defined for the applet:


 

One nice thing about Java applets is that, once they are downloaded to the client, the next time they are invoked, they don't have to be downloaded again. Let's face it: The Internet is slow, and downloading large Java applets can be time consuming, especially over a slow modem. Caching applets on the client can save a lot of time. Each time the Web page is revisited, the browser checks to see whether the applet has already been downloaded and makes sure that it has the correct version. If the version has changed or the cached applet no longer exists on the client, it is downloaded.

When a Java applet is created, many class files usually make up the application. To help manage this, a Java Archive (JAR) file can be created to package all the class files into a single archive file. A JAR file is, essentially, a ZIP file that contains all the class and auxiliary files necessary to execute an applet. A JAR file compresses the files, making them quicker to transmit over slow network connections.

In addition to easier management of Java files, one advantage of JAR files is security. JAR files can be digitally signed. When a user accepts a digitally signed JAR file, the applet could be granted security privileges that it might not otherwise have on the client machine.


 

ActiveX COM

Overview of Modeling and Web-Related Technologies

Building Web Applications



Building Web Applications With UML
Building Web Applications with UML (2nd Edition)
ISBN: 0201730383
EAN: 2147483647
Year: 2002
Pages: 141
Authors: Jim Conallen

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net