10 Jan 1997


Java is a new computer programming language developed by Sun Microsystems. Java has a good chance to be the first really successful new computer language in several decades. Advanced programmers like it because it has a clean, well-designed definition. Business likes it because it dominates an important new application, Web programming.

Java has several important features:

A group at Sun reluctantly invented Java when they decided that existing computer languages could not solve the problem of distributing applications over the network. C++ inherited many unsafe practices from the old C language. Basic was too static and constrained to support the development of large applications and libraries.

Today, every major vendor supports Java. Netscape incorporates Java support in every version of its Browser and Server products. Oracle will support Java on the Client, the Web Server, and the Database Server. IBM looks to Java to solve the problems caused by its heterogeneous product line.

Microsoft distributes Java with Internet Explorer, with its Visual J++ development environment, and with a free Java SDK that can be downloaded from www.microsoft.com. This version of Java support installs directly into the Windows directory and becomes an extension of the operating system. Microsoft has also added features to the Java execution support (to the "virtual machine") so that Java programs can act as OLE clients or servers. This makes Java a full-fledged Windows development language, but it enrages Sun because programmers can now develop Java programs that depend on OLE and are no longer portable to all systems.

Modular Construction with Class Files

Conventional application programs are based on large EXE and DLL files containing machine instructions for a particular CPU. An EXE built for Windows NT running on an Intel chip cannot run on a Windows NT system based on an Alpha or PowerPC CPU. EXE files are large, and loading them through the network would take a very long time.

Java programs are based on smaller *.class files. (The change of case from "EXE" to "class" reflects the new file naming conventions of NT and Windows 95 which allows the file extension to be four instead of just three characters and allows file names with lower case letters.) Each *.class file provides either one component of a specific application or a general purpose package of related routines.

A Java program begins when the browser loads an applet class file over the network or when the Interpreter loads an application class file from local disk. This first class calls other classes, which in turn call other classes. A Loader component in the Interpreter searches for each class by name starting with the libraries on the local disk and then extending to the Web server that transmitted the applet. Because the class files are smaller than conventional programs, and because they are loaded only when needed, Java minimizes the burden placed on the network. Even then it may still take some time for an applet to load over a modem.

A programmer creates a class by editing an ordinary text file with any editor (Windows Notepad will word, but there are better editors designed for writing programs). The file has an extension of *.java and is written following the rules of the Java programming language. The Java compiler (javac.exe) converts the *.java source file into a *.class file. The *.class file can then be directly run on any computer with a Java Interpreter.

More abstractly, a Class defines a combination of data and operations necessary to perform a particular operation. The Java language contains a class called "Math" that defines useful numbers (e and pi) and useful functions (sin, log, random). They could have separated out the trig functions to make the class smaller, but learning all the class names is already a major part of learning the Java language. Ultimately, deciding what goes into a class and what forms a separate class is the major task in Java program design.

A Class can perform the same operation using several different types of input. For example, a VCR taping can be scheduled by entering a day, time, channel, and length, or it can be scheduled using the VCR+ codes in the newspaper listings. When a language, such as Java, supports different functions with the same name and different input, this feature is called "overloading." However, Java does not go as far as C++ and other languages which allow the programmer to redefine primitive operations symbols like "+" to call user defined functions.

Every time a programmer looks over some code, he sees a better way to do things. Sometimes a program can be improved by just changing the calculation, but it is often necessary to change the way information is stored. A time of day might be initially stored in hours, minutes, and seconds. Then someone realizes that it is faster to just save it as 24*60*60 seconds. In a conventional language, like C++, the application has to be rebuilt every time a programmer changes some class that it uses. One small change can produce an avalanche of rebuilding. In Java, a change to a class doesn't effect any other files, unless it deletes or alters a public data item or operation.

Any program written in the Java language can store data, compute, and call other classes. In order to open a disk file, use the network, or query a database, a Java program must call what appears to be another Class but what is really a program written in C. This is called a "native" class. Native classes cannot be loaded through the network, and the native classes supplied with the browser or Java Interpreter do not allow applet programs (loaded through the network) to access disk files or databases on the client's own machine or on the client's local network. This allows anyone to write their own Java programs that work like any application, but also protects you from security problems if an applet is loaded from some other location.

Applets and the AWT

A program written in Java should run exactly the same on Windows, a Macintosh, or a Unix system. Yet each system has a different method of coding the user interface. The Abstract Windows Toolkit (AWT) provides a set of Java Classes that provide the standard set of user interface elements (windows, menus, boxes, buttons, lists, etc.).

Developing AWT objects directly with a text editor is an almost impossible task. Symantec offers a tool called Visual Café for Windows or Macintosh users. The programmer can drag and drop user interface elements from a toolbar, then control them with a properties table. Although the development environment runs on a specific system, the resulting code is pure Java and can be executed on Unix, OS/2, or any other platform that supports Java.

A stand-alone Java application program may choose to use character mode I/O within the command prompt window, or it may create AWT objects and use the graphic user interface. However, an Applet (a Java program loaded through the network from a Web server to a browser) must create a window that resides within a Web document. In technical terms, the "Applet" Class is a special version of the "Window" Class and has to carve out some rectangular gray area in the document. It may choose to populate that area with user interface objects, or it could leave it blank, but the area has to exist.

HTML reserves an area on the page for the Applet just as it handles a GIF file. The Applet window has a height and width in dots and initially displays as a gray box. The Applet program has to fill the area with user interface objects or animation.

A Java program has access only to the services and data exposed by the native Class library. None of the current browsers provide the classes which allow an applet to validate data entered into an HTML FORM, or even to interrogate the URL of a document or load a new URL into a new window or frame. Currently, the applet environment is completely isolated from the HTML. Netscape supports a different language (JavaScript) for use with FORM elements.

The Java applet hitches a ride on a Web document. It depends on HTML for its distribution. But once it is loaded, a Java applet stands on its own and communicates only through a low level Internet programming service back to the server machine from which it was loaded.

Server-Side Java

In the Netscape 2.x Servers, when a URL specifies a program in the directory named "server-java/", then the name of the program is actually a Java *.class file. Performance in the original 2.0 Servers was terrible, so anyone planning to use this facility should upgrade to the 2.01 release of the Server.

Since Java is an interpreted language, these programs can be run directly by the Server without the cost of creating a new process. The Java class is loaded once, and then remains resident so it can be reused by subsequent requests. Threads are a native feature of Java, and the Java programmer learns how to handle them properly.


Copyright 1996 PC Lube and Tune -- Distributed Applications and the Web H. Gilbert