Skip to main content.

Web Based Programming Tutorials

Homepage | Forum - Join the forum to discuss anything related to programming! | Programming Resources

JAVA Developer's Guide

Chapter 1 -- The Java Phenomenon

Chapter 1

The Java Phenomenon


In its brief existence, the World Wide Web has evolved into a truly global information space. Not only does it offer information on any subject, it provides its citizens with the power to globally publish information on any subject and at minimal cost. The massive international participation in the Web has resulted in the creation of many Web pages that are not only informative, but also entertaining. This entertainment value has further fueled the Web's growth and has led to browsing becoming an international pastime.

Browsing involves scanning Web pages for interesting information, following useful links to other pages, and repeating the process until we come across something that makes us temporarily stop and focus. Sometimes we mutter, "Hmm" or "That's interesting!" and create a bookmark. Then, eventually, we move on.

The tendency to move on and continue browsing is natural. We usually don't read the same book over and over. If we have a stack of magazines in front of us, we're likely to flip through them all. Web pages are like magazine pages, except that they are more available, usually free, and have more "next" pages to which to turn.

Computer programs are different. They are active, while books, magazines, and Web pages are static or passive. People do use programs over and over. I still use WordPerfect 5.1. Some people still use CP/M. I have a friend who played DOOM several hours a day for months.

This difference between active computer programs and passive Web pages is what makes Java an attractive addition to the Web. When we click on a Web page containing a Java applet, we don't just read it, listen to it, or watch it-we interact with it. Interactivity is the difference between a program and a page, and Java has brought dynamic, interactive content to the Web.

Java's rapidly growing popularity is due to the Web. But Java's inherent power does not come from the fact that it is a Web programming language. The talented software engineers at Sun, in bringing Java to the Web, have elegantly solved a much broader and more significant problem-how to develop network-capable windowing software that will run on almost any 32-bit computer and operating system.

The modern software developer faces enormous headaches and challenges when he tries to develop software that is portable to Microsoft Windows, X Window systems, Motif, MacOS, and OS/2 windowing and networking environments. The usual approach is to pick a target operating system (OS), write software for that OS, and eventually migrate it to the other OS platforms. This usually involves great expense in terms of labor and software development resources.

Java fulfills the software developer's dream of being able to write software in a single language that will support windowing and networking on all major OS platforms, without specialized tailoring or even recompilation. But Java's attractiveness does not end here. Sun's engineers were thoughtful enough to develop in Java a language and runtime system that are simple, compact, object-oriented, extendible, and secure. And then they gave it away for free!

The objective of this book is to provide an introduction to using the gift of Java in its broader context-as a platform-independent software development language. Java's capabilities to provide interactive content to Web pages, in the form of applets, are covered within this broader context, but these capabilities do not limit the focus of the book's presentation.

What Is Java?

Forrest Gump might say that Java is as Java does. Java is a programming language, a runtime system, a set of development tools, and an application programming interface (API). The relationships between these elements are depicted in Figure 1.1.

Figure 1.1 : Java unveiled.

As illustrated in Figure 1.1, a software developer writes programs in the Java language that use predefined software packages of the Java API. The developer compiles his or her programs using the Java compiler. This results in what is known as compiled bytecode. Bytecode is in a form that can be executed on the Java virtual machine, the core of the Java runtime system. You can think of the virtual machine as a microprocessor that is implemented in software and runs using the capabilities provided by your operating system and computer hardware. Since the Java virtual machine is not a real microprocessor, the Java bytecode is interpreted, rather than executed directly in the native machine instructions of the host computer. (There are plans to make it possible to translate Java bytecode into machine code on-the-fly.) The Java runtime system consists of the virtual machine plus additional software, such as dynamic link libraries, that are needed to implement the Java API on your operating system and hardware.

The Java API contains predefined software packages with numerous platform-independent "hooks" into the native windowing and networking capabilities of the host operating system. The Java API provides a single common API across all operating systems to which Java is ported.

The keys to Java's portability are its runtime system and its API. The runtime system is very compact, evolving from earlier Sun efforts to build a software platform for consumer electronics. This platform was not designed around any existing microprocessor; it was built from scratch to be simple and efficient. The fact that it was not tied to a given hardware architecture enabled it to be architecture neutral. The simple, efficient, compact, and architecture-neutral nature of the runtime system allows it to be highly portable and still provide effective performance.

The powerful windowing and networking features included in the Java API make it easier for programmers to develop software that is both attractive and platform independent. For example, Ada is a programming language that is highly standardized and supported on most operating systems. Yet Ada applications are not very portable. This is because Ada does not come with a common API that supports windowing and networking on all platforms. Java differs from Ada and all other programming languages in that there is one universal, but powerful, Java API for all operating system platforms. That is why Java is the most portable language.

The Origins of Java

At this point, you may wonder how Sun's engineers were able to develop such a powerful software development environment and surpass all known programming languages. The answer is they didn't-at least not directly. Java evolved from other research projects at Sun.

The development of Java wasn't as accidental or monumental as the discovery of penicillin, but it shares some of its characteristics. The origins of Java trace back to 1991, when Sun was investigating consumer electronics products. At this time, Mosaic and the World Wide Web were just interesting concepts.

James Gosling, the father of Java, was intent on building a low-cost, hardware-independent software platform using C++. For a number of technical reasons, C++ was dropped, and a new language, called Oak, was developed, based on C++, but eliminating its shortcomings. These shortcomings include problems associated with multiple inheritance, automatic type conversion, the use of pointers, and memory management.

Oak was used to develop a small electronics device called *7. This project resulted in the precursors of many of the components of Java: the development environment, runtime system, and API. The technology was explored in a number of consumer applications but was a little ahead of its time.

By 1994 the Web emerged, Oak was renamed Java, and the proverbial light bulb went on in the minds of the Java developers. Java was used as the basis for a Web browser, called WebRunner. WebRunner was successfully demonstrated, and the Java/HotJava project took off.

HotJava, Java, and the Java documentation and source code were made available over the Web, as an alpha version, in early 1995. Initially Java was hosted on SPARC Solaris, and then on Windows NT. In the summer of 1995, Java was ported to Windows 95 and Linux. In the fall of 1995 the Java Beta 1 version was released through Sun's Web site, and Java support was introduced in the Netscape 2.0 browser.

The Java Beta 1 release led scores of vendors to license Java technology, and Java porting efforts were initiated for all major operating systems.

In December 1995 the Java Beta 2 version was released, and JavaScript was announced by Sun and Netscape. Java's success became inevitable when, in early December, both Microsoft and IBM announced their intention to license Java technology.

On January 23, 1996, Java 1.0 was officially released and made available for download over the Internet. JavaScript was also released. Netscape 2.0 now provides support for both Java and JavaScript.

Why Program in Java?

So far we have touched on only two reasons to program in Java-it is platform independent and it supports interactive content on Web pages. Does this mean that Java is for everybody? Certainly not!

If you are developing highly complex, performance-critical number crunching algorithms for a Cray computer, then Java is probably not the language for you. Try FORTRAN. If you are developing patches to legacy code from the 1970s, you might use COBOL. If you are developing software for the U.S. Department of Defense, you should probably use Ada.

So, for what types of software applications is Java well suited? The answer is almost everything else. Figure 1.2 summarizes the types of applications at which Java excels.

Figure 1.2 : Where Java excels.

Because of its intended use on the Web, where even the smallest security vulnerability could potentially be exploited and cause global mayhem, Java was designed with multiple layers of security countermeasures embedded in the compiler, runtime system, and in browsers that support Java, known as Java-enabled browsers. These countermeasures make Java inherently more secure for developing any type of trusted application software. Chapter 39, "Java Security," is devoted to Java security.

Java is exceptionally well suited to distributed networking applications because of its built-in networking support and the runtime system's capability to dynamically load Java bytecode across the network. Java also provides the capability to dynamically utilize new content and protocol handling software. The HotJava browser, written in Java, is an excellent example of Java's distributed networking capabilities.

Java is a sound choice for developing software where reliability is of utmost concern, such as mission-critical applications. Java's object-oriented nature combined with numerous, compile-time and runtime integrity checks eliminate many difficult-to-find programming errors. The Java language has removed many of the dangerous programming capabilities, such as modifiable pointers, unchecked type conversion, and relaxed bounds checking, that are commonly found in other programming languages, such as C and C++.

The Java API provides full support of multithreaded programming. Multithreaded programs can be developed in a single, consistent manner, independent of the vagaries of the host operating system interface.

Java classes and objects directly support the object-oriented concepts of encapsulation, inheritance, messages and methods, and data hiding. Java interfaces provide support for multiple inheritance and polymorphism. The Java language retains all the benefits of object-oriented programming without the performance impacts associated with pure object languages, such as Smalltalk.

The Java API provides extensive support of windowing and graphical user interface development without the complexities associated with maintaining multiple window class libraries. Several visual programming tools have been developed for Java.

Java and HotJava

My first experience with Java was through an early version of HotJava. Java and HotJava are sometimes confused. Java is the language, development and runtime environments, and API. HotJava is a Web browser that is written in Java. HotJava highlights many of the Java features mentioned in the previous section.

HotJava is a Java-enabled browser. This means that HotJava can execute Java applets contained on Web pages. In order to accomplish this, HotJava calls the Java runtime system. The Netscape 2.0 browser, like HotJava, is also Java enabled. It contains a copy of the Java runtime system embedded within it. Figure 1.3 illustrates the operation of HotJava and other Java-enabled browsers.

Figure 1.3 : How HotJava and Netscape 2.0 support Java applets.

Both HotJava and Netscape request Web pages, written in HTML, from Web servers on the Internet. Since HotJava is written in Java, it uses the Java API and runtime system to display the Web pages to a user. Netscape, on the other hand, is written in C++ and uses C++ functions to display HTML documents.

When either browser encounters an APPLET tag in an HTML file, it requests the Java bytecode file necessary to execute the applet from the Web server. HotJava loads and executes the bytecode file using the Java runtime system. Netscape executes the bytecode file using an embedded version of the Java runtime system.


This chapter provides a brief description of Java's capabilities. It explains what Java is and why you should be interested in learning to use Java. It also summarizes the history of Java's development. In the next chapter, you will receive a more detailed overview of the Java language, the Java Developer's Kit, and the application programming interface.