Java Developer's Reference

Peter Kitson

ISBN : 1575211297

Order a printed copy of this book from Amazon.


Cover Design - Java Developer's Reference
 

For your free electronic copy of this book please verify the numbers below. 

(We need to do this to make sure you're a person and not a malicious script)

Numbers

 




Sample Chapter From Java Developer's Reference
     Copyright © Mike Cohn, Bryan Morgan, Michael Morrison, Michael T. Nygard, Dan Joshi, Tom Trinko



What Is Java?

Java was developed at Sun Microsystems. Work on Java originally began with the goal of creating a platform-independent language and operating system for consumer electronics. The original intent was to use C++, but as work progressed in this direction, the Java developers realized that they would be better served by creating their own language rather than extending C++. The effort toward consumer electronics led the Java team, then known as FirstPerson, Inc., toward developing hardware and software for the delivery of video-on-demand with Time-Warner.

Unfortunately (or perhaps fortunately, depending on your perspective), Time-Warner selected Silicon Graphics as the vendor for its video-on-demand project. This setback left the FirstPerson team with an interesting piece of software (Java) but no market in which to place it. Eventually, the natural synergies of the Java language and the World Wide Web (WWW) were noticed, and Java found a market.

What we know today as Java is both a programming language and an environment for executing programs written in the Java language. Unlike traditional compilers, which convert source code into machine-level instructions, the Java compiler translates Java source code into instructions that are interpreted by the runtime Java Virtual Machine. So, unlike languages like C and C++, on which Java is based, Java is an interpreted language.

Although most of the current excitement and anticipated use of Java are related to the Internet, and the World Wide Web in particular, Java did not begin as an Internet project. Because of this, Java is suitable for many general-purpose programming tasks and, in fact, many of the Java tools themselves are written in Java. It is a compiler development custom that a language has come of age when its compiler can be written in the language. According to this custom, the Java language has come of age.

Java as an Internet Language

The excitement over Java as an Internet development language is related to its capability to solve two key problems with Internet content:

  • Currently, the WWW content is passive and static.
  • Delivery of WWW content is dependent on the configuration of each user\'s Web browser.

Although these two problems are related, each warrants independent consideration.

Passive and Static Content

Current WWW pages are very good at conveying some types of information but are inadequate for conveying other types. In particular, WWW pages excel at conveying passive, static information. This type of information changes infrequently (static) and doesn\'t change in response to user interactions with it (passive).

For example, many Web pages enable you to enter a company\'s name or stock ticker symbol and receive current price quotes. One of the best is the APL Quote Server located at http://qs.secapl.com/cgi-bin/qs and shown in Figure 1.1. This page is static because it isn\'t automatically updated with new quotes while the page is being browsed. It is passive because the user cannot interact with the page, other than to request to see a similar page.

Figure 1.1 : Retrieving passive, static stock prices.

Current Web development technologies excel at displaying this type of page. Much of human communication is passive, static, or both. A highway billboard is a perfect example of a conventional means of communication that is both passive and static. Just as not all billboards will go the way of Burma Shave, not all passive, static WWW content needs to become active and dynamic (the opposites of passive and static).

However, Java is an enabling technology that allows for the creation of more powerful pages. Continuing with the example of a page that shows the price of a stock at a given point in time, you could use Java to create a page that shows a graph of a stock\'s price over time and have that graph continue to update in real time while you browse the page. This is where Java comes in-because Java is a full-featured programming language, Web pages like this become much more feasible. Sun Microsystems has created a page that does exactly this. It is located at

http://java.sun.com/java.sun.com/applets/applets/StockDemo/index.html

and is shown in Figure 1.2.

Figure 1.2 : A Java version of a stock price Web page.

On the Java WWW page shown in Figure 1.2, there is a line of stock ticker symbols and prices that scrolls across the top of the screen. Below that are graphs for three different companies\' stocks. Each of these graphs is updated every five seconds based on the latest trades. (The page shown in Figure 1.2 is just an illustration and the prices of the NEATO company are randomly generated.)

Freedom from Browser Configuration

In the pre-Java world of the Web, as a developer of Web content and pages, you could not count on your users having a specific browser configuration. You could create a Web page with leading edge graphics, sound, and real-time multimedia. Unfortunately, if any of the visitors to your Web site did not configure a browser add-on to handle the latest whiz-bang features, these users wouldn\'t get the full impact of your site.

Just as the prior section showed that Java enabled applications to go beyond passive, static content, Java again serves as an enabling technology. In this case, Java enables you, as a Web developer, to create Web pages that will be delivered consistently to all users with a Java-enabled browser.

Not only does Java free you from concerns about how users have configured their Web browsers, it also frees you from concerns about which hardware and operating system platform they are using. Because Java source code is interpreted, if a Java interpreter exists for a specific hardware and operating system platform, you can write programs with the knowledge that they will be usable on that platform.

How It Works

Now that you\'ve read about some of the benefits of using Java for World Wide Web applications, it\'s time to take a quick look behind the scenes at how this is accomplished. Figure 1.3 shows how Java source code is transferred over the Internet. This figure shows a host computer that is storing the source code to a Java program. When a user on a local computer uses the Internet to connect to this host with a Java-enabled browser, the source is transferred from the host computer to the local computer.

Figure 1.3 : Transfer of Java source code over the Internet.

Implemented within the Java-enabled browser is the Java Virtual Machine, which interprets the Java source code. The Java Virtual Machine acts on an input byte stream and converts it into the desired program actions. In the case of Java, the byte stream is a sequence of opcodes (operation codes) and operands. Each pair of opcode and operand is read by the interpreter, and the specified action is performed. This is illustrated in Figure 1.4.