Java Reference
In-Depth Information
Many HTML tags can contain attributes that further describe how the tag
should format text, align objects, and so on. Attributes typically take the form
<tag attribute=“value”>
For example, as shown in line 43 of Figure 12-7 on page 787, the <font> tag
includes a size attribute, which is set to a value of 6, using the code
<font size=“6”>WebStocks</font>
to set the font size of the word, WebStocks, to 6. A tag often can include several
attributes; the <font> tag, for example, has attributes of size, color, face, and more.
Editing HTML code using a text editor, as opposed to using a GUI Web page
editor, can be confusing. Code readability is improved by using good indentation
as well as color syntax highlighting, if your text editor supports that feature.
Writing HTML Code
If you create HTML documents with a GUI Web page editor, the
HTML tags often are created for you; however, reading the code
can be difficult. If you code HTML with a text editor, such as
TextPad, using syntax highlighting and indenting the tags in a
consistent manner improves readability, which also improves
maintainability.
Using JavaScript in an HTML Document
Some of the HTML and JSP files in this chapter also contain a small amount
of JavaScript code, such as that shown in lines 12 through 28 in Figure 12-7.
JavaScript is often confused with Java and sometimes with JSP. As you learned in
Chapter 1, JavaScript is a scripting language used to insert functionality within
an HTML document. Netscape Navigator and Microsoft Internet Explorer both
support JavaScript, so that if you include JavaScript in an HTML document, you
can use either of these browsers to interpret it.
JavaScript syntax is similar to Java, as well as C and C++, but is a simpler
language than Java and supports less functionality. JavaScript is object-based ;
that is, it uses built-in objects. JavaScript uses an object model to reference built-
in objects. Two such built-in objects are the document object , which is the
HTML document, and the window object , which is the browser window. Unlike
Java, however, JavaScript cannot create hierarchies of user-defined objects.
JavaScript can define variables by using the keyword, var , as in
var myData;
however, the variable is undefined in value and has no declared data type until
a value is assigned.
JavaScript is case-sensitive and has statements and operators similar to
Java. Ending JavaScript statements with a semicolon is optional; however, it is
recommended practice to use them, making the code easier to relate to Java.
Search WWH ::




Custom Search