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.
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.
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>
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: