Java Reference
In-Depth Information
To execute your program, the Java interpreter analyzes and then executes the byte code instructions.
The Java virtual machine is identical in all computer environments supporting Java, so you can be sure
your program is completely portable. As we already said, your program will run just as well on a Unix
Java implementation as it will on that for Windows 95/98/NT/2000/XP, for Solaris, Linux, OS/2, or
any other operating system that supports Java. (Beware of variations in the level of Java supported
though. Some environments, such as the Macintosh, tend to lag a little, so implementations for Java 2
will typically be available later than under Windows or Solaris.)
Executing an Applet
Note that the Java compiler in the SDK will compile both applications and applets. However, an applet is not
executed in the same way as an application. You must embed an applet in a web page before it can be run.
You can then execute it either within a Java 2-enabled web browser, or by using the appletviewer , a bare-
bones browser provided as part of the SDK. It is a good idea to use the appletviewer to run applets while
you are learning. This ensures that if your applet doesn't work, it is almost certainly your code that is the
problem, rather than some problem in integration with the browser.
If you have compiled an applet and you have included it in a web page stored as MyApplet.html in
the current directory on your computer, you can execute it by entering the command:
appletviewer MyApplet.html
So how do you put an applet in a web page?
The Hypertext Markup Language
The HyperText Markup Language, or HTML as it is commonly known, is used to define a web page. If
you want a good, compact, reference guide to HTML, I recommend the topic Instant HTML
Programmer's Reference (Wrox Press, ISBN 1-861001-56-8). Here we will gather just enough on HTML so
that you can run a Java applet.
When you define a web page as an HTML document, it is stored in a file with the extension .html . An
HTML document consists of a number of elements, and each element is identified by tags . The
document will begin with <html> and end with </html> . These delimiters, <html> and </html> ,
are tags, and each element in an HTML document will be enclosed between a similar pair of tags
between angle brackets. All element tags are case insensitive, so you can use uppercase or lowercase, or
even a mixture of the two, but by convention they are capitalized so they stand out from the text. Here
is an example of an HTML document consisting of a title and some other text:
<html>
<head>
<title>This is the title of the document</title>
</head>
<body>
You can put whatever text you like here. The body of a document can contain
all kinds of other HTML elements, including <B>Java applets</B>. Note how each
element always begins with a start tag identifying the element, and ends with
an end tag that is the same as the start tag but with a slash added. The pair
of tags around 'Java applets' in the previous sentence will display the text
as bold.
Search WWH ::




Custom Search