This is an archive copy of the Crystallography World Wide component of the IUCr web site dating from 2008. For current content please visit the NEWS, PEOPLE and RESOURCES sections of https://www.iucr.org.
[IUCr Home Page] [Crystallographer's Guide to Internet Tools and Resources]

Java: A Brief Introduction

Java, unlike HTML, is a programming language. This means to create something in Java, you should have a basic knowledge of programming. Java can be used to write stand alone programs, called applications, or for programs that run within a web page, called applets.

Java Example Programs

These are a few example java applets to get you started with Java. This first Java program is the most simple. It is a short Hello World applet. The applet is only a few lines long, without any interactivity.

The second example is also very simple, but allows very basic interaction with the user. When the applet first starts up, it shows a message 0 ms.. When the mouse pointer enters, it saves the clock time to a variable, and changes the background color to red. When the mouse leaves the applet, the background goes to white, and the time the mouse was in the applet is displayed in milliseconds.

The last example is fairly complex. It reads in a molecular data file in Cartesian coordinates, and then displays it as a wireframe model. This model can then be rotated on the web page.

Including Java in a Web Page

To run Java on a web page, the applet must be embeded within an HTML document. This is done with the <APPLET> tag. This tag can be used to specify a Java applet, its size, as well as any parameters that are specific to that applet.

The starting <APPLET> tag has several components. These include the applet name (Java program to be executed), as well as the width and height of the applet, within the HTML page. An optional codebase (directory the applet resides in) can also be included. An applet named Test.class, in the java directory (relative to the httpd home), with a width of 20 and height of 10, would look like this:

    <APPLET CODEBASE="/java" CODE="Test.class" WIDTH=20 HEIGHT=10>
    </APPLET>
Notice the tag closer, </APPLET>. All parameter files go between the <APPLET> tag and the </APPLET> tag. If you wanted to include an HTML tag that would be seen on a browser that could not see your applet (a non Java-enabled browser), then that code would also be between the <APPLET> and </APPLET> tags. Note that this extra code is ignored by browsers that are Java enabled.

A parameter tag for an applet has two fields in it containing its name and its value. Let's say our previous example had a parameter called color, and we wanted to set it to red. Let's also assume that we want to load an image called NoJava.gif for use by a non-Java enabled browser. The code would then look like this:

    <APPLET CODEBASE="/java" CODE="Test.class" WIDTH=20 HEIGHT=10>
    <PARAM NAME="color" VALUE="red">
    <IMG SRC="NoJava.gif">
    </APPLET>

Java Resources

There are over 100 books on Java at this time, and listing them all here would just be useless. There are several places you can obtain a listing of all java related books, as well as pricing and reviews. These include:

For general information on Java, there are many sites devoted to the Java programming language. Here are a few of the more widely used sites:


[Index] - 26th September 1996 - © John N. Huffman and John C. Huffman - Not to be copied or reproduced without permission - Author's current manuscipt