Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Taking_Your_Talent_to_the_Web.pdf
Скачиваний:
5
Добавлен:
11.05.2015
Размер:
9.91 Mб
Скачать

344 HOW: Beyond Text/Pictures: Cookin’ with Java

In Illustrator, you can recombine basic button shapes, spirals, or complex outlines to create new artwork from predesigned fragments. Similarly, a Java programmer can combine entire libraries worth of coded objects to build new programs from existing parts. Reusing graphic elements makes you faster and more productive; reusing code objects does the same thing for Java programmers.

Reusable parts: that’s the idea. Sun’s programmers called these parts objects. Sun didn’t invent this idea. Windows, Mac OS, and UNIX also reuse code objects (Windows DLLs, anyone?). But in operating systems like Windows, Mac OS, and UNIX, these reusable parts are immediately compiled down to machine code. In Java, they are compiled to an intermediary format called “bytecode,” which is then interpreted by a Java Virtual Machine, about which we’ll have more to say in just a moment.

As mentioned earlier in this chapter, Java can be used to create full-scale programs (applications), miniature programs that download quickly when needed (applets), or server-side servlets. Servlets are full-fledged but small application fragments that run in the context of the server—as Photoshop plug-ins run in the context of Photoshop.

Ghost in the Virtual Machine

But there’s a catch. Just as Windows programs require a Windows environment and Mac programs are designed for Macs, Java programs must run in a Java environment.

Does this mean that you have to go out and buy a Java computer? No, it simply means that Java programs are designed to run in Java-capable web browsers (Netscape Navigator, Microsoft Internet Explorer), Java-capable web-enabled devices, or special Java devices (such as Java-powered digital television-top boxes and remotes). They do this by means of Java Virtual Machines, which we promise, really truly promise, we will describe in just a moment.

Netscape was the first browser to support Java, and the point of the Sun/Netscape partnership, as explained in Chapter 2, was to smash Windows hegemony while getting Java onto as many platforms as possible, by way of the browser. They succeeded at getting Java onto as many platforms as possible. One out of two ain’t bad.

Taking Your Talent to the Web

345

Today most browsers and computer operating systems support Java. It gets a bit more complicated when the browser or OS maker offers an “improved” Java environment that Sun does not consider truly Java-compatible, but we’ll get to that later. Java-capable browsers might run on any computing platform (Windows, Mac OS, Linux, UNIX, or BeOS) as long as the browser manufacturer supports that platform.

What makes all of this work? The Java Virtual Machine does. You might think of the Virtual Machine as a streamlined computer operating system (OS) running inside another computer OS—a Java computer running inside Windows, for example. Or you might think of it as an interpreter, turning spoken words into sign language for the hearing-impaired.

This Virtual Machine is sometimes included with the browser. Early versions of Netscape included a Virtual Machine customized for each OS. This added significantly to the download time but ensured that users would have the then-new Java technology at their disposal.

In other cases, the Virtual Machine is built into the operating system. For instance, Apple Macintosh OS9 includes “Mac OS Runtime for Java,” a Java Virtual Machine whose sole purpose is to run Java programs on the Mac.

If you install IE5 Macintosh Edition on a pre-OS 9 Mac, you might get Java errors because IE5/Mac expects a more recent Virtual Machine than the one on your system. You can correct this problem by upgrading to OS9 or by downloading a more recent version of Mac OS Runtime for Java from http://developer.apple.com/java/classic.html. The program is free.

As you can see, the tantalizing potential of Java lies in its ability to work in any operating system equipped with a Java Virtual machine—in other words, theoretically at least, to run on any operating system. Practically speaking, developers could build a word processor or a full-blown office suite that runs in any Java-capable web browser and on any operating system with a Virtual Machine. Of course, companies that make word processors and full-blown office suites might not like that idea. They might dislike it so much that they would end up building their own web browser and taking over the market…not that we’re mentioning any names. There is, in fact, a Java word processor (indeed, there is an entire Java office suite), and we hear it works quite well.

346 HOW: Beyond Text/Pictures: Cookin’ with Java

Where the web designer fits in

As a web designer, you might be called upon to embed a Java applet in an HTML page. (Again: An applet is a self-contained piece of code that runs within a Java-capable browser, as Photoshop plug-ins run within Photoshop.) This is simply a matter of using the HTML <OBJECT> or <APPLET> tag or another very basic HTML tag—no problem at all. At other times, you might use Java to compensate for a missing plug-in on a visitor’s system.

For instance, the IpixViewer plug-in, like Apple’s QuickTime VR (see the section, "Turn on, Tune in, Plug-in" later in this chapter), enables visitors to explore 360º panoramic views of any location that can be photographed. It’s an extraordinary plug-in that does a remarkable job. But not many people know about this plug-in, so not many have downloaded it. Therefore you might feel that IpixViewer content cannot be used on your site. Not to worry! The missing plug-in can be replaced by a Java applet and compiled down to native, platform-specific code via the Java Virtual Machine:

<applet name=”IpixViewer” code=”IpixViewer.class” archive=”IpixViewer.jar” height=”210”width=”280”>

<param name=”URL” value=”zabptcaj.ipx”> <param name=”Spin” value=”on”> </applet>

If the HTML just listed looks odd to you, don’t sweat it. Your Java developer will tell you what needs to be included on the page. Your job will be to insert it, test it, and verify things such as height and width. (Is the resulting image in fact 210 pixels high? Does it look right? If not, change the numbers and try again.) By the way, this same technique works for other multimedia content, such as Flash. If the visitor lacks the Flash plug-in, a Java applet can display the Flash content. Your developers will create the applet and the complex code that determines whether or not the applet is needed on each visitor’s system. Your job is simply to plug in some HTML and test.

The other reason you need to know about Java is that in spite of its utopian aims and utilitarian benefits, Java can sometimes be problematic. And as a user-oriented web designer, you need to be aware of that.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]