We close this chapter with a list of some common misconceptions about Java, along with commentary. Java is an extension of HTML. Java is a programming language; HTML is a way to describe the structure of a web page. They have nothing in common except that there are HTML extensions for placing Java applets on a web page. I use XML, so I don't need Java. Java is a programming language; XML is a way to describe data. You can process XML data with any programming language, but the Java API contains excellent support for XML processing. In addition, many important third-party XML tools are implemented in Java. See Volume 2 for more information. Java is an easy programming language to learn. No programming language as powerful as Java is easy. You always have to distinguish between how easy it is to write toy programs and how hard it is to do serious work. Also, consider that only four chapters in this book discuss the Java language. The remaining chapters of both volumes show how to put the language to work, using the Java libraries. The Java libraries contain thousands of classes and interfaces, and tens of thousands of functions. Luckily, you do not need to know every one of them, but you do need to know surprisingly many to use Java for anything realistic. Java will become a universal programming language for all platforms. This is possible, in theory, and it is certainly the case that every vendor but Microsoft seems to want this to happen. However, many applications, already working perfectly well on desktops, would not work well on other devices or inside a browser. Also, these applications have been written to take advantage of the speed of the processor and the native user interface library and have been ported to all the important platforms anyway. Among these kinds of applications are word processors, photo editors, and web browsers. They are typically written in C or C++, and we see no benefit to the end user in rewriting them in Java. Java is just another programming language. Java is a nice programming language; most programmers prefer it over C, C++, or C#. But there have been hundreds of nice programming languages that never gained widespread popularity, whereas languages with obvious flaws, such as C++ and Visual Basic, have been wildly successful. Why? The success of a programming language is determined far more by the utility of the support system surrounding it than by the elegance of its syntax. Are there useful, convenient, and standard libraries for the features that you need to implement? Are there tool vendors that build great programming and debugging environments? Does the language and the tool set integrate with the rest of the computing infrastructure? Java is successful because its class libraries let you easily do things that were hard before, such as networking and multithreading. The fact that Java reduces pointer errors is a bonus and so programmers seem to be more productive with Java, but these factors are not the source of its success. Now that C# is available, Java is obsolete. C# took many good ideas from Java, such as a clean programming language, a virtual machine, and garbage collection. But for whatever reasons, C# also left some good stuff behind, most important security and platform independence. In our view, the biggest advantage of C# is its excellent development environment. If you are tied to Windows, C# makes a lot of sense. But judging by the job ads, Java is still the language of choice for a majority of developers. Java is proprietary, and it should therefore be avoided. Everyone will need to make up their own mind on this issue. There are times when we are frustrated by some aspect of Java, and we wish that a competing open-source team could provide salvation. But the situation isn't that simple. Although Sun has ultimate control over Java, they have, through the "Java Community Process" involved many other companies in the development of language revisions and the design of new libraries. Source code for the virtual machine and the libraries is freely available, but only for inspection, not for modification and redistribution. Looking at the open-sourced languages out there, it is not clear that they are doing a better job. The most popular ones are the three "Ps" in "LAMP" (Linux, Apache, MySQL, and Perl/PHP/Python). These languages have their benefits, but they have also suffered from disruptive version changes, limited libraries, and a paucity of development tools. On the other side of the spectrum we have C++ and C# that were standardized by vendor-independent standards committees. We agree that this process is more transparent than the Java Community Process. However, the results have not been as useful as you might think. It is not enough to standardize just the language and the most basic libraries. For real programming, you quickly go beyond string handling, collections, and files. In the case of C#, Microsoft has gone on record stating that they will keep most libraries outside the standardization process. Perhaps the future of Java lies in an open-source process. But at this point, Sun has convinced a lot of people that it is a responsible steward of Java. Java is interpreted, so it is too slow for serious applications. In the early days of Java, the language was interpreted. Nowadays, except on "micro" platforms such as cell phones, the Java virtual machine uses a just-in-time compiler. The "hot spots" of your code will run just as fast in Java as they would in C++. Java does have some additional overhead over C++ that has nothing to do with the virtual machine. Garbage collection is slightly slower than manual memory management, and Java programs are more memory-hungry than C++ programs with similar functionality. Program startup can be slow, particularly with very large programs. Java GUIs are slower than their native counterparts because they are painted in a platform-independent manner. People have complained for years that Java is slower than C++. However, today's computers are much faster than they were when these complaints started. A slow Java program will still run quite a bit better than those blazingly fast C++ programs did a few years ago. At this point, these complaints sound like sour grapes, and some detractors have instead started to complain that Java user interfaces are ugly rather than slow. All Java programs run inside a web page. All Java applets run inside a web browser. That is the definition of an applet a Java program running inside a browser. But it is entirely possible, and quite useful, to write stand-alone Java programs that run independently of a web browser. These programs (usually called applications) are completely portable. Just take the code and run it on another machine! And because Java is more convenient and less error-prone than raw C++, it is a good choice for writing programs. It is an even more compelling choice when it is combined with database access tools like Java Database Connectivity (see Volume 2). It is certainly the obvious choice for a first language in which to learn programming. Most of the programs in this book are stand-alone programs. Sure, applets are fun. But stand-alone Java programs are more important and more useful in practice. Java programs are a major security risk. In the early days of Java, there were some well-publicized reports of failures in the Java security system. Most failures were in the implementation of Java in a specific browser. Researchers viewed it as a challenge to try to find chinks in the Java armor and to defy the strength and sophistication of the applet security model. The technical failures that they found have all been quickly corrected, and to our knowledge, no actual systems were ever compromised. To keep this in perspective, consider the literally millions of virus attacks in Windows executable files and Word macros that cause real grief but surprisingly little criticism of the weaknesses of the attacked platform. Also, the ActiveX mechanism in Internet Explorer would be a fertile ground for abuse, but it is so boringly obvious how to circumvent it that few have bothered to publicize their findings. Some system administrators have even deactivated Java in company browsers, while continuing to permit their users to download executable files, ActiveX controls, and Word documents. That is pretty ridiculous currently, the risk of being attacked by hostile Java applets is perhaps comparable to the risk of dying from a plane crash; the risk of being infected by opening Word documents is comparable to the risk of dying while crossing a busy freeway on foot. JavaScript is a simpler version of Java. JavaScript, a scripting language that can be used inside web pages, was invented by Netscape and originally called LiveScript. JavaScript has a syntax that is reminiscent of Java, but otherwise there are no relationships (except for the name, of course). A subset of JavaScript is standardized as ECMA-262, but the extensions that you need for real work have not been standardized, and as a result, writing JavaScript code that runs both in Netscape and Internet Explorer is an exercise in frustration. With Java, I can replace my computer with a $500 "Internet appliance." When Java was first released, some people bet big that this was going to happen. Ever since the first edition of this book, we have believed it is absurd to think that home users are going to give up a powerful and convenient desktop for a limited machine with no local storage. We found the Java-powered network computer a plausible option for a "zero administration initiative" to cut the costs of computer ownership in a business, but even that has not happened in a big way. On the other hand, Java has become widely distributed on cell phones. We must confess that we haven't yet seen a must-have Java application running on cell phones, but the usual fare of games and screen savers seems to be selling well in many markets. TIP
|