Sams Teach Yourself JavaScript in 24 Hours

Sams Teach Yourself JavaScript in 24 Hours

By Michael Moncur

Alternatives to JavaScript

JavaScript is not the only language used on the Web, and in some cases, it may not be the right tool for the job. Other languages, such as Java, can do some things better than JavaScript. In the following sections, we'll look at a few other commonly used Web languages and their advantages.

Java

Java is a programming language developed by Sun Microsystems that can be used to create applets, or programs that execute within a Web page.

Java is a compiled language, but the compiler produces code for a virtual machine rather than a real computer. The virtual machine is a set of rules for bytecodes and their meanings, with capabilities that fit well into the scope of a Web browser.

The virtual machine code is then interpreted by a Web browser. This allows the same Java applet to execute the same way on PCs, Macintoshes, and UNIX machines, and on different browsers.

At this point, we need to make one thing clear: Java is a fine language, but you won't be learning it in this book. Although their names and some of their commands are similar, JavaScript and Java are entirely different languages.

ActiveX

ActiveX is a specification developed by Microsoft that allows ordinary Windows programs to be run within a Web page. ActiveX programs can be written in languages such as Visual C++ and Visual Basic, and they are compiled before being placed on the Web server.

ActiveX applications, called controls, are downloaded and executed by the Web browser, like Java applets. Unlike Java applets, controls can be installed permanently when they are downloaded, eliminating the need to download them again.

ActiveX's main advantage is that it can do just about anything. This can also be a disadvantage: Several enterprising programmers have already used ActiveX to bring exciting new capabilities to Web pages, such as "the Web page that turns off your computer" and "the Web page that formats your disk drive. "

Fortunately, ActiveX includes a signature feature that identifies the source of the control and prevents controls from being modified. While this won't prevent a control from damaging your system, you can specify which sources of controls you trust.

ActiveX has two main disadvantages. First, it isn't as easy to program as a scripting language or Java. Second, ActiveX is proprietary: it works only in Microsoft Internet Explorer, and only under Windows platforms.

VBScript

VBScript, sometimes known as Visual Basic Scripting Edition, is Microsoft's answer to JavaScript. Just as JavaScript's syntax is loosely based on Java, VBScript's syntax is loosely based on Microsoft Visual Basic, a popular programming language for Windows machines.

Like JavaScript, VBScript is a simple scripting language, and you can include VBScript statements within an HTML document. To begin a VBScript script, you use the <script LANGUAGE="VBScript"> tag.

VBScript can do many of the same things as JavaScript, and it even looks similar in some cases. It has two main advantages:

VBScript's main disadvantage is that it is supported only by Microsoft Internet Explorer. JavaScript, on the other hand, is supported by Netscape, Internet Explorer, and several other browsers. JavaScript is a much more popular language, and you can see it in use all over the Web.

CGI and Server-Side Scripting

CGI (Common Gateway Interface) is not really a language, but a specification that allows programs to run on Web servers. CGI programs can be written in any number of languages, including Perl, C, and Visual Basic.

Along with traditional CGI, scripting languages such as Microsoft's Active Server Pages, Java Server Pages, Cold Fusion, and PHP are often used on Web servers. A server-side implementation of JavaScript is also available.

Server-side programs are heavily used on the Web. Any time you type information into a form and press a button to send it to a Web site, the data is processed by a server-side application.

The main difference between JavaScript and server-side languages is that JavaScript applications execute on the client (the Web browser) and server-side applications execute on the Web server. The main disadvantage of this approach is that, since the data must be sent to the Web server and back, response time may be slow.

On the other hand, CGI can do things JavaScript can't do. In particular, it can read and write files on the server and interact with other server components, such as databases. While a client-side JavaScript program can read information from a form and then manipulate it, it can't store the data on the Web server.

Share ThisShare This

Informit Network