Chapter 34. How Java, ActiveX, and JavaScript Work

Chapter 34. How Java, ActiveX, and JavaScript Work

The Internet is no longer a place that you visit with your computer and merely look at documents or gather informationincreasingly, it is an extension of your computer. You can now run programs that reside on the Internet rather than on your own computer, and tools have been developed that enable your computer and the Internet to interact as if they were one large computer system. This allows for all kinds of things never before possible: news tickers that flash breaking news; interactive games; multimedia presentations combining animation, sound, and music; and much more.

Three important programming tools associated with web technology are Java, ActiveX, and JavaScript. Java, a computer language developed by Sun Microsystems, enables applications to be run from the Internetthe same as word processing and spreadsheet programs are run on your computer. It is similar to the C++ computer programming language and is object-oriented, which means programs can be created by using many preexisting components instead of by a programmer writing the entire program from scratch. Although most Java programs are run from the Internet, they don't have to be and can be run just like any other type of program.

Java programs run inside your web browser if you have a Java-enabled browser, such as Netscape. When Java programs are run inside a browser, they are called applets. You don't need to do anything to run a Java applet. When you visit a website that has a Java applet on it, the applet is downloaded automatically from a web server and then run automatically in your browser. Java applets can be run on any computer, such as a PC, a Macintosh, or a Unix workstation.

ActiveX, a technology from Microsoft, enables Internet programmers to create programscommonly referred to as ActiveX controls or componentsthat can essentially turn the Internet into an extension of your computer. Similar to Java applets, these controls are downloaded to your computer and run there. They can do anything a normal application can do, in addition to interacting with the Web, the Internet, and other computers connected to the Internet. To run these controls, a browser that supports ActiveX, such as Internet Explorer, is necessary.

One benefit of ActiveX controls is that they are written as components, which means they can be put together, much like building blocks, to build larger and more complex applications. Another benefit is that, because you have already downloaded a component, you won't ever need to download it again. So, when you visit a page with a complex ActiveX application on it, you might need to download only a small portion of it because you might already have the other components on your computer.

JavaScript is a scripting language that is less complex and therefore much easier to learn than Java and ActiveX. People without substantial programming experience can write scripts with JavaScript. It's also an interpreted language, which means that its commands are executed by the browser in the order in which the browser reads them. It's commonly used for things such as creating drop-down boxes, navigational aids, and interactive forms, although it can be used for creating more complex applications, as well.

How Java Works

Java is a compiled language, which means that after a Java program is written, the program must be run through a compiler to turn the program into a language a computer can read. Java differs from other compiled languages, however. In other compiled languages, computer-specific compilers create distinct executable binary code for all the different computers on which the program can run. In Java, by contrast, a single compiled version of the programcalled Java bytecodeis created by a compiler. Interpreters on different computers, such as a PC, Macintosh, or SPARC workstation, understand the Java bytecode and run the program. In this way, a Java program can be created once and then used on many types of computers. Java programs designed to run inside a web browser on the World Wide Web are called applets. Java-enabled browsers contain Java bytecode interpreters.