Java Reference
In-Depth Information
Executing Applets Using the Web
In order for the applet to be transmitted over the Web and executed by a browser,
it must be referenced in a HyperText Markup Language (HTML) document. An
HTML document contains tags that specify formatting instructions and identify
the special types of media that are to be included in a document. A Java program
is considered a specific media type, just as text, graphics, and sound are.
An HTML tag is enclosed in angle brackets. The following is an example of
an applet tag:
<applet code="Einstein.class" width="350" height="175">
</applet>
This tag dictates that the bytecode stored in the file Einstein.class should be trans-
ported over the network and executed on the machine that wants to view this particu-
lar HTML document. The applet tag also indicates the width and height of the applet.
There are other tags that can be used to reference an applet in an HTML file,
including the <object> tag and the <embed> tag. The <object> tag is actually the
tag that should be used, according to the World Wide Web Consortium (W3C).
However, browser support for the <object> tag is not consistent. For now, the most
reliable solution is to use the <applet> tag.
Note that the applet tag refers to the bytecode file of the Einstein applet, not to the
source code file. Before an applet can be transported using the Web, it must be compiled
into its bytecode format. Then, as shown in Figure 2.11, the document can be loaded
using a Web browser, which will automatically interpret and execute the applet.
Java source
code
Across the
Internet
using HTML
Java
bytecode
Java compiler
Java
interpreter
Bytecode
compiler
Web browser
Java
interpreter
Machine
code
Local computer
Remote computer
FIGURE 2.11 The Java translation and execution process, including applets
 
Search WWH ::




Custom Search