Network computing
(c) 1996 IBM Corporation

Introduction

The following chapters are an excerpt from The Visual Basic Programmer's Guide to Java by James W. Cooper, published by Ventana Books. James W. Cooper is a Research Staff Member at IBM's Thomas J. Watson Research Center and the author of 10 books in the field.

Chapter 1: What is Java?

The Genesis of Java (TM)

The Java language was designed at Sun Microsystems over a 5 year period, culminating in its first release in January, 1996. The developers, led by James Gosling, originally had in mind building a language for controlling simple home devices with embedding microcomputers. Thus, they started with the object oriented concepts of C++, they simplified it and removed some of the features such as pointers that lead to serious programming errors.

While the team may originally have had in mind compiling this language for a specific microprocessor, they developed both the Java language and a hypothetical processor called the Java Virtual Machine or JVM. The Java compilers they developed produced binary code designed to execute on this JVM rather than on a PC or Sun workstation.

They relate that their working name for this evolving language was "Oak," but as it neared completion they found that this trademark was already registered. So, the story goes, they came up with the name "Java" while taking a break at a coffee shop.

Executing Java Programs on Real Computers

Then, to actually execute Java programs, they developed Java interpreters that ran on various machines and under various operating systems. Thus, Java became a language that would execute on a number of systems and now has implementations for virtually all common computers and operating systems.

Sometime during development, it suddenly became obvious that Java would be an ideal language for use in the rapidly exploding Internet. They added a window manager to allow easy development of user interfaces and added network communication methods such as web page URLs and sockets.

Since Java could now run on nearly any kind of workstation, it became an ideal vehicle for adding powerful computational capabilities to web pages. You could browse these pages from any platform and see the same behavior in the embedded Java program.

Java Applets

A Java applet is a program designed to be embedded in a web page. Applets can be quite complex: they are not limited to simple animations or single windows and may access remote databases or other sources of information, and may load and operate on complex information on your computer system.

Java applets are designed to be quite secure, however, so that they can be safely downloaded over a network without your being concerned that they might be able to do damage or mischief to your computer.

They cannot write any information onto your hard disk unless you specifically declare a directory which applets have access to. They cannot access any other resources on your network or any other hardware or peripherals on your computer.

The Netscape version 2.x and 3.x browsers impose additional protection: they do not allow applets to write any files to your disk even if you define a directory which you allow applets to write to.

Java applets are also restricted from writing into memory outside the Java address space. This is accomplished mainly through the fact that Java has no memory pointer type and thus cannot have this pointer pointing to memory a malicious programmer might want to attack. Java applets are also scrutinized class by class as they are loaded by the run time environment in your browser, and checks are made to assure that the binary code has not been modified such that it might interact with or change any part of the memory of your system.

Further, applets cannot access resources on any other computer on your network or elsewhere on the Internet with one exception: they can open TCP/IP connections back to the machine running the web server they were downloaded from.

To add even more protection and prevent programmers from spoofing users into giving them confidential information, all windows which you pop up from an applet have a banner along the bottom reading "Untrusted Java Applet." This is to prevent hackers from designing an exact copy of a familiar screen and luring users to type confidential information into it.

Java Applications

By contrast, Java applications are full-featured programs which run on your computer and have full access to its resources. They can read, write, create and delete files, and access any other computer on the network.

You will quickly appreciate that it is possible to develop full-fledged applications in Java: database viewers, word processors, spreadsheets, math packages, file and network manipulation programs. In fact, one of the great strengths of Java is that it makes accessing other computers on your network extremely easy.

Now you can write quite sophisticated programs in Visual Basic as well, so you might ask whether Java is really "ready" for all this attention. Can you write real, significant programs in Java? Figure 1-1 shows a simple data entry program for a search tool, allowing you to enter terms as well as Boolean conditions from drop-down list boxes. Figure 1-2 shows the exact same program created in Java.

Figure 1-1: A simple search query entry form, written in Visual Basic.

Figure 1-2: The same simple search query entry form written in Java.

Both of these are complete, working programs and their sources and binaries are included on the example disk, under \chapter1, If you want to see how they work.

But what about Java? How does it really stack up? Is it real or is it a toy? Let's take a moment and look at some of the advantages of each language.

Advantages of Visual Basic

  1. Visual Basic has an excellent GUI building environment. The Form editor which allows you to drag and drop any of a large number of visual controls onto a form and attach code to them is as yet unsurpassed. However, by the time this book is published, any number of GUI builders should be available in mature second versions from companies like Symantec, Rogue Wave, Borland and Microsoft which have roughly the same functionality as Visual Basic.
  2. Visual Basic has more visual controls. Since VB has been around much longer, there are more third party vendors supplying GUI controls for the development environment. However, this is already much less true than even 3 months ago: vendors have produced grid controls, toolbars, tree lists and picture buttons. Further we'll soon see how easy it is to write your own controls in Java: something not for the faint of heart in VB.
  3. Visual Basic allows easy access to databases. Many, many programmers start working in VB because it provides easy access to databases. Java allows this too, as we will see in a later chapter.

Advantages of Java

  1. Java is object oriented. Writing code in Java requires that you write 100% object-oriented code. As we will see, once we spend a few minutes learning about OO programming, such programs are easier to write and easier to maintain than the spaghetti code that VB can lead to.
  2. Java works on most platforms. While VB is exclusively a Windows product, Java binary byte code runs identically on most Unix machines, Macintoshes, and PC's running Windows 95, Windows NT, OS/2 and Linux.
  3. Java is network enabled. It is trivially simple to write code in Java that works across networks. The use of URLs, TCP sockets and remote classes is essentially built into the language.
  4. Java is multithreaded. You can write programs where several sections run simultaeously in different execution threads.
  5. Java allows you to add major function to web pages. If you are interested in building interactive world wide web pages that compute, collect or display data, Java is the language of choice. There simply is not a better way to add interactive controls to web pages.

With all of these pluses, the only possible drawback is that you'll have to learn a new language. This is, of course, what this book is about and we'll see some very significant advantages to Java as we begin to explore it.

Moving On

So far, we've looked at the reason Java was designed and compared it briefly to Visual Basic. Next we'll look at how to install Java and compile Java programs. Then, to become fluent in Java, you'll need to learn two things: Java's syntax, and the rationale behind object oriented programming. We'll take these up in the following chapters, and soon you, too, will be a Java expert.


Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.

[Top of page] | [Next chapter] | [Java expertise]