JavaScript, Java Applets, and DHTML

JavaScript

JavaScript, developed by Netscape, is a scripting language that is widely supported by web browsers. JavaScript is considered to be a client-side scripting language--it runs on the web client (the browser) and not the web server. This makes them portable across any browser that includes JavaScript support, regardless of the computer type or operating system. Although most modern browsers support JavaScript, they also offer an option to disable it, so it's important not to count on every user having it.

JavaScript is an object-based scripting language which means that you use JavaScript to work with objects and elements associated with web pages: browser windows, forms, images, and links. It is often used to respond to events such as moving the mouse, clicking a button, and loading a web page. It is also often used for checking input values in forms.

JavaScript can be placed in a separate file (with a .js extension) and accessed by a web browser, but JavaScript is more commonly embedded directly in the web page along with the HTML. JavaScript code can be added to a web page in two ways:

  1. Place JavaScript code between <script> tags

  2. Place JavaScript code as part of an event attached to an HTML element

Below are some examples of how JavaScript is used. Be sure to view the source code to see how JavaScript has been added to the page.

Java Applets

Java is an object-oriented programming language developed by Sun Microsystems. Java is not the same language as JavaScript. Java is a full-blown programming language, whereas JavaScript is a scripting language that is much more limited in scope. Java programs can be called from Web pages or run stand alone. When launched from a Web page, the program is called a Java "applet." Java applets are platform independent--which means they can be written and run on any platform. Java applets are compiled and saved as .class files which are interpreted by the web browser.

To include an applet on a Web page, you will use the <applet> tag. The opening <applet> tag specifies the beginning of an applet area and the closing </applet> specifies the ending of an applet area. The common attributes for the <applet> tag are code, width, and height.  The code attribute will tell the browser where to find the Java applet file which will have a .class or .java file extension.  The width and height attributes define the size of the applet area in pixels. 

In addition, most applets need special values, or parameters, to configure their processing. The <param> tag is used between the open and close <applet> tags to define parameters for the applet. The two attributes included in the <param> tag are name and value.  The name attribute assigns a name to the parameter and the value attribute is the information to be passed on to the applet.  Each applet requires different parameters and should be provided to you in the applet documentation. When a Java applet loads, the area reserved for it on the web page displays a gray box until the applet begins to execute.

Below are some examples of how Java applets are used:

Dynamic HTML (DHTML)

Dynamic HTML is a group of technologies that work together to change a web page after it has been downloaded. The three technologies used are the Document Object Model (DOM) which defines every object and element on the web page, Cascading Style Sheets (CSS) which is used to apply formatting to the web page, and a scripting language such as JavaScript, VBScript or JScript, which are used to access the DOM and manipulate the elements.

The code needed to add a DHTML effect to a web page varies depending on the desired effect. The coding can get complex because DHTML is implemented differently in different browsers and browser versions and you will need to know the syntax required for these various browsers. It is also a good idea to become comfortable with CSS and JavaScript before tackling DHTML.

Examples of how DHTML is used: