Part 1: Basic Info and Examples
|The Need for Something New|
|What is Java Script and Java Applets|
|Who can create Java Script and Applets, and Who Can Use Them|
|How to use Java Script and Java Applets |
|Writing Your Own Java Script-enhanced Web Pages|
Web pages can incorporate formatted text and graphics elements to present information in an esthetically pleasing form. You can even enhance the information content by adding hyperlinks to more information, or to other types of documents.
|Web pages are static, i.e. the content does not change over time (no animation possible)|
|Web pages are not interactive, i.e. the content does not change depending on the user's action|
|Links to other types of documents require so-called helper applications that may or may not be installed at the user's computer|
|The types of documents that can be accessed is limited, i.e. you can not include a Lotus 123, an SPSS, or a DBASE file in a Web page|
To overcome these deficiencies, a mechanism called CGI Scripts is usually used:
CGI (Common Gateway Interface) scripts are programs that are installed on the Web server - not the web client - and that can process information that a Web client such as Netscape gives them. Almost all forms, for example, are filled out on the client, and then submitted to a server, where a CGI script processes the information and delivers an appropriate response. A very common mechanism is a Search, where the user enter some key phrases, the CGI script searches a database for appropriate responses, and delivers those back to the user's client program.
CGI scripts can overcome the first two problems,
|CGI scripts do not provide helper applications to a client computer|
|CGI scripts are usually machine-dependent, i.e. if a script can perform a task on one machine (say a SUN workstation) the same script may or may not work correctly on another system (say a PC running a Windows Web server program)|
|CGI scripts are processed at the server. If many people use a particular server, it may become pretty slow, lowering overall performance even for those people who do not use the CGI scripts.|
|Not everyone can create CGI scripts. In fact, usually only people with special accounts on the server machine can write CGI scripts. As an example, on our machine only Andrew Pu and myself can write CGI scripts. This restriction is necessary for security reasons.|
Java Script and Java Applets are convenient methods to provide
|animation and content that changes over time|
|interative documents that change depending on a user's response|
|links to new types of documents without the need of a helper application|
|ability to process any type of document, without need of a helper application|
In addition, the provide advantages over CGI scripts, since:
|Java is machine-independent, i.e. it runs on IBM, Macintosh, and Unix machine without modifications|
|Anyone can create Java Scripts and Java applets, without special privileges|
|Java Script programs are reasonably easy to create|
|Java is its own, full, object-oriented programming language and provides many, many more features than are possible with CGI scripts|
|Java Scripts and Applets run on the client machine, keeping the load off the server|
Java Script is a simple, object-oriented, interpreted programming language that provides methods (or functions), commands, and event handlers that can be embedded right into an HTML document. You do not need to compile your commands, and you do not need any special programs to create Java Script programs. Java Script programs run on any machine using a Java Script-aware browser such as Netscape. Java Script programs are limited in their abilities, and they since they are interpreted line by line, they are slow.
Java is an object-oriented, very complete, machine independend programming language that can be used to create either stand-alone programs or programs that are embedded in a Java-aware Web browser (such programs are then called applets). The Java programs need to be compiled before they can be used, and you need a special Java compiler to create the Java programs. Java programs run on any machine as standalone programs, complete with Graphical User Interface, or they can be embedded into a Java-aware browser such as Netscape. Java programs can incorporate almost any features, including graphics, menu, and networking features, that are expected of any other Windows program, and since it is a compiled language, it runs fast. To write a Java program or applet, you must create the source code in a *.java file and then compile it into a byte-code file called *.class. The class file then contains the runable applet or program.
Anybody who can create HTML pages can also create Java Script programs embedded in an HTML document. No special privileges are needed, and no special software or hardware needs to be used.
In theory, anybody can also create Java programs, which could be either embedded into an HTML document, or distributed as a stand-alone program for any type of computer. However, it is not trivial to create Java programs, and you need at least:
|Programming knowledge (object-oriented variety preferred)|
|Windows 95 or brand of UNIX|
|The Java Development Kit (contains Java compiler)|
|Documentation about available Java classes|
If you created a standalone Java program, anybody could use it (if they can access it). If you created a Java applet (a Java program embedded into a Web page), and you placed the program and the corresponding page on a Web server, then anybody who has a Java-aware browser can use your program without further setup.
To use Java applets, on the other hand, is very easy - if you find an existing one that will serve your purpose. To write the Java applet yourself, on the other hand, is not at all easy, and you are better of to try to locate an existing applet that can do what you want.
- Netscape 1.1 and below:
- not Java aware
- Netscape 2.0 and above:
Java aware for Macintosh, Windows 95, and Unix
- a special Java-aware browser for Windows 95 and Unix systems, Java aware (with restrictions)
- Any other browser:
To use Java applets in a page you need to have:
|An applet in byte-code (i.e. with .class extension) |
|An applet in source code (.java) and the Java compiler|
|Documentation about the applet, stating the name and meaning of any parameters the applet can take|
To use the applet, simply put the <APPLET> and the </APPLET> tag together with the appropriate parameters into your HTML document and the applet will run at the indicated spot.
The Applet tag has the following form:
<APPLET CODEBASE="basedir" CODE="filename.class" WIDTH="xxx" HEIGHT="xxx"> <PARAM NAME="param_name" VALUE="param_value"> <PARAM NAME="param_name" VALUE="param_value"> <...> </APPLET>
For non-Java aware browsers, you can put any standard HTML code and/or tags between the APPLET tags. It will be ignored by the Java-aware browser, while the non-Java aware browser will display it and ignore the APPLET and PARAM tags.
(Bert G. Wachsmuth)