The Java™ Language Environment: Awhitepaper
The Java™ Language Environment: Awhitepaper
The Java™ Language Environment: Awhitepaper
AWhitePaper
JamesGosling
HenryMcGilton
JavaSoft
2550 Garcia Avenue
Mountain View, CA 94043 U.S.A
408-343-1400
May 1996
Copyright Information
1995, 1996, 1997 Sun Microsystems, Inc. All rights reserved.
2550 Garcia Avenue, Mountain View, California 94043-1100 U.S.A.
This documentat is protected by copyright. No part of this document may be reproduced in any form by any means without
prior written authorization of Sun and its licensors, if any.
The information described in this document may be protected by one or more U.S. patents, foreign patents, or pending
applications.
TRADEMARKS
Sun, the Sun logo, Sun Microsystems, Solaris, HotJava, and Java are trademarks or registered trademarks of Sun
Microsystems, Inc. in the U.S. and certain other countries. The “Duke” character is a trademark of Sun Microsystems, Inc., and
Copyright (c) 1992-1995 Sun Microsystems, Inc. All Rights Reserved. UNIX is a registered trademark in the United States and
other countries, exclusively licensed through X/Open Company, Ltd. OPEN LOOK is a registered trademark of Novell, Inc.
All other product names mentioned herein are the trademarks of their respective owners.
X Window System is a trademark of the X Consortium.
THIS DOCUMENT IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
THIS DOCUMENT COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS. CHANGES ARE
PERIODICALLY ADDED TO THE INFORMATION HEREIN; THESE CHANGES WILL BE INCORPORATED IN NEW
EDITIONS OF THE DOCUMENT. SUN MICROSYSTEMS, INC. MAY MAKE IMPROVEMENTS AND/OR CHANGES IN
THE PRODUCT(S) AND/OR THE PROGRAM(S) DESCRIBED IN THIS DOCUMENT AT ANY TIME.
Please
Recycle
Contents
1. Introduction to Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.1 Beginnings of the Java Language Project. . . . . . . . . . . . . . 12
1.2 Design Goals of Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.2.1 Simple, Object Oriented, and Familiar . . . . . . . . . . . 13
1.2.2 Robust and Secure. . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.2.3 Architecture Neutral and Portable . . . . . . . . . . . . . . 14
1.2.4 High Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.2.5 Interpreted, Threaded, and Dynamic . . . . . . . . . . . . 15
1.3 The Java Platform—a New Approach to Distributed
Computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2. Java—Simple and Familiar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.1 Main Features of the Java Language . . . . . . . . . . . . . . . . . 20
2.1.1 Primitive Data Types . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.1.2 Arithmetic and Relational Operators . . . . . . . . . . . . 21
2.1.3 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.1.4 Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
iv
2.1.5 Multi-Level Break . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.1.6 Memory Management and Garbage Collection . . . 24
2.1.7 The Background Garbage Collector . . . . . . . . . . . . . 25
2.1.8 Integrated Thread Synchronization . . . . . . . . . . . . . 25
2.2 Features Removed from C and C++ . . . . . . . . . . . . . . . . . . 26
2.2.1 No More Typedefs, Defines, or Preprocessor . . . . . 26
2.2.2 No More Structures or Unions . . . . . . . . . . . . . . . . . 27
2.2.3 No Enums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.2.4 No More Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.2.5 No More Multiple Inheritance. . . . . . . . . . . . . . . . . . 29
2.2.6 No More Goto Statements . . . . . . . . . . . . . . . . . . . . . 30
2.2.7 No More Operator Overloading . . . . . . . . . . . . . . . . 30
2.2.8 No More Automatic Coercions . . . . . . . . . . . . . . . . . 30
2.2.9 No More Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3. Java is Object Oriented . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.1 Object Technology in Java . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.2 What Are Objects? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.3 Basics of Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.3.1 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.3.2 Instantiating an Object from its Class. . . . . . . . . . . . 35
3.3.3 Constructors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.3.4 Methods and Messaging . . . . . . . . . . . . . . . . . . . . . . 38
3.3.5 Finalizers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Contents vi
6.3.1 The Byte Code Verifier . . . . . . . . . . . . . . . . . . . . . . . . 63
6.4 Security in the Java Networking Package . . . . . . . . . . . . . 64
6.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
7. Multithreading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
7.1 Threads at the Java Language Level . . . . . . . . . . . . . . . . . 66
7.2 Integrated Thread Synchronization . . . . . . . . . . . . . . . . . . 67
7.3 Multithreading Support—Conclusion . . . . . . . . . . . . . . . . 68
8. Performance and Comparisons. . . . . . . . . . . . . . . . . . . . . . . . . . 70
8.1 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
8.2 The Java Language Compared . . . . . . . . . . . . . . . . . . . . . . 71
8.3 A Major Benefit of Java: Fast and Fearless Prototyping. . 74
8.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
9. Java Base System and Libraries . . . . . . . . . . . . . . . . . . . . . . . . . 76
9.1 Java Language Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
9.2 Input Output Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
9.3 Utility Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
9.4 Abstract Window Toolkit. . . . . . . . . . . . . . . . . . . . . . . . . . . 79
10. The HotJava World-Wide Web Browser . . . . . . . . . . . . . . . . . . 82
10.1 The Evolution of Cyberspace . . . . . . . . . . . . . . . . . . . . . . . 83
10.1.1 First Generation Browsers . . . . . . . . . . . . . . . . . . . . . 84
10.1.2 The HotJava Browser—A New Concept in Web Browsers
85
10.1.3 The Essential Difference . . . . . . . . . . . . . . . . . . . . . . . 85
10.1.4 Dynamic Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Contents viii
ix The Java Language Environment—May 1996
Introduction to Java 1
10
1
The tools you use to develop applications don’t seem to help you much. You’re
still coping with the same old problems; the fashionable new object-oriented
techniques seem to have added new problems without solving the old ones.
You say to yourself and your friends, “There has to be a better way”!
You don’t need to dream about these features. They’re here now. The Java
Programming Language platform provides a portable, interpreted, high-
performance, simple, object-oriented programming language and supporting run-
time environment. This introductory chapter provides you with a brief look at
the main design goals of the Java system; the remainder of this paper examines
the features of Java in more detail.
The massive growth of the Internet and the World-Wide Web leads us to a
completely new way of looking at development and distribution of software.
To live in the world of electronic commerce and distribution, Java must enable
the development of secure, high performance, and highly robust applications on
multiple platforms in heterogeneous, distributed networks.
Introduction to Java 12
1
Operating on multiple platforms in heterogeneous networks invalidates the
traditional schemes of binary distribution, release, upgrade, patch, and so on.
To survive in this jungle, Java must be architecture neutral, portable, and
dynamically adaptable.
The Java system that emerged to meet these needs is simple, so it can be easily
programmed by most developers; familiar, so that current developers can easily
learn Java; object oriented, to take advantage of modern software development
methodologies and to fit into distributed client-server applications;
multithreaded, for high performance in applications that need to perform
multiple concurrent activities, such as multimedia; and interpreted, for
maximum portability and dynamic capabilities.
Java is designed to be object oriented from the ground up. Object technology has
finally found its way into the programming mainstream after a gestation
period of thirty years. The needs of distributed, client-server based systems
coincide with the encapsulated, message-passing paradigms of object-based
software. To function within increasingly complex, network-based
environments, programming systems must adopt object-oriented concepts.
Java provides a clean and efficient object-based development platform.
Programmers using Java can access existing libraries of tested objects that
provide functionality ranging from basic data types through I/O and network
interfaces to graphical user interface toolkits. These libraries can be extended
to provide new behavior.
The memory management model is extremely simple: objects are created with
a new operator. There are no explicit programmer-defined pointer data types,
no pointer arithmetic, and automatic garbage collection. This simple memory
management model eliminates entire classes of programming errors that
bedevil C and C++ programmers. You can develop Java language code with
confidence that the system will find many errors quickly and that major
problems won’t lay dormant until after your production code has shipped.
Architecture neutrality is just one part of a truly portable system. Java takes
portability a stage further by being strict in its definition of the basic language.
Java puts a stake in the ground and specifies the sizes of its basic data types
and the behavior of its arithmetic operators. Your programs are the same on
every platform—there are no data type incompatibilities across hardware and
software architectures.
Introduction to Java 14
1
The architecture-neutral and portable language platform of Java is known as
the Java Virtual Machine. It’s the specification of an abstract machine for which
Java language compilers can generate code. Specific implementations of the
Java Virtual Machine for specific hardware and software platforms then
provide the concrete realization of the virtual machine. The Java Virtual
Machine is based primarily on the POSIX interface specification—an industry-
standard definition of a portable system interface. Implementing the Java
Virtual Machine on new architectures is a relatively straightforward task as
long as the target platform meets basic requirements such as support for
multithreading.
While the Java compiler is strict in its compile-time static checking, the
language and run-time system are dynamic in their linking stages. Classes are
linked only as needed. New code modules can be linked in on demand from a
variety of sources, even from sources across a network. In the case of the
HotJava browser and similar applications, interactive executable code can be
loaded from anywhere, which enables transparent updating of applications.
The result is on-line services that constantly evolve; they can remain innovative
and fresh, draw more customers, and spur the growth of electronic commerce
on the Internet.
Introduction to Java 16
1
18
2
chapter discusses Java’s object-oriented features in more detail. At the end of
this chapter you’ll find a discussion on features eliminated from C and C++ in
the evolution of Java.
Design Goals
Simplicity is one of Java’s overriding design goals. Simplicity and removal of
many “features” of dubious worth from its C and C++ ancestors keep Java
relatively small and reduce the programmer’s burden in producing reliable
applications. To this end, Java design team examined many aspects of the
“modern” C and C++ languages* to determine features that could be
eliminated in the context of modern object-oriented programming.
To illustrate the simple and familiar aspects of Java, we follow the tradition of
a long line of illustrious programming books by showing you the HelloWorld
program. It’s about the simplest program you can write that actually does
something. Here’s HelloWorld implemented in Java.
class HelloWorld {
static public void main(String args[]) {
System.out.println("Hello world!");
}
}
This example declares a class named HelloWorld. Classes are discussed in the
next chapter on object-oriented programming, but in general we assume the
reader is familiar with object technology and understands the basics of classes,
objects, instance variables, and methods.
Within the HelloWorld class, we declare a single method called main() which
in turn contains a single method invocation to display the string "Hello world!"
on the standard output. The statement that prints "Hello world!" does so by
Real numeric types are 32-bit float and 64-bit double. Real numeric types
and their arithmetic operations are as defined by the IEEE 754 specification. A
floating point literal value, like 23.79, is considered double by default; you
must explicitly cast it to float if you wish to assign it to a float variable.
2.1.3 Arrays
In contrast to C and C++, Java language arrays are first-class language objects.
An array in Java is a real object with a run-time representation. You can declare
and allocate arrays of any type, and you can allocate arrays of arrays to obtain
multi-dimensional arrays.
You declare an array of, say, Points (a class you’ve declared elsewhere) with a
declaration like this:
Point myPoints[];
The length of an array is stored in the length instance variable of the specific
array: myPoints.length contains the number of elements in myPoints. For
instance, the code fragment:
howMany = myPoints.length;
The C notion of a pointer to an array of memory elements is gone, and with it,
the arbitrary pointer arithmetic that leads to unreliable code in C. No longer
can you walk off the end of an array, possibly trashing memory and leading to
the famous “delayed-crash” syndrome, where a memory-access violation today
manifests itself hours or days later. Programmers can be confident that array
checking in Java will lead to more robust and reliable code.
2.1.4 Strings
Strings are Java language objects, not pseudo-arrays of characters as in C.
There are actually two kinds of string objects: the String class is for read-only
(immutable) objects. The StringBuffer class is for string objects you wish to
modify (mutable string objects).
Although strings are Java language objects, Java compiler follows the C
tradition of providing a syntactic convenience that C programmers have
enjoyed with C-style strings, namely, the Java compiler understands that a
string of characters enclosed in double quote signs is to be instantiated as a
String object. Thus, the declaration:
String hello = "Hello world!";
This code fragment concatenates the string "There are " with the result of
converting the numeric value num to a string, and concatenates that with the
string " characters in the file.". Then it prints the result of those
concatenations on the standard output.
The continue test statement is inside a for loop nested inside another for
loop. By referencing the label test, the continue statement passes control to
the outer for statement. In traditional C, continue statements can only
continue the immediately enclosing block; to continue or exit outer blocks,
programmers have traditionally either used auxiliary Boolean variables whose
only purpose is to determine if the outer block is to be continued or exited;
The notion of labelled blocks dates back to the mid-1970s, but it hasn’t caught
on to any large extent in modern programming languages. Perl is another
modern programming language that implements the concept of labelled
blocks. Perl’s next label and last label are equivalent to continue label and
break label statements in Java.
Java completely removes the memory management load from the programmer.
C-style pointers, pointer arithmetic, malloc, and free do not exist. Automatic
garbage collection is an integral part of Java and its run-time system. While Java
has a new operator to allocate memory for objects, there is no explicit free
function. Once you have allocated an object, the run-time system keeps track of
the object’s status and automatically reclaims memory when objects are no
longer in use, freeing memory for future use.
Java’s memory allocation model and automatic garbage collection make your
programming task easier, eliminate entire classes of bugs, and in general
provide better performance than you’d obtain through explicit memory
management. Here’s a code fragment that illustrates when garbage collection
happens:
class ReverseString {
public static String reverseIt(String source) {
int i, len = source.length();
StringBuffer dest = new StringBuffer(len);
This use of a thread to run the garbage collector is just one of many examples
of the synergy one obtains from Java’s integrated multithreading
capabilities—an otherwise intractable problem is solved in a simple and
elegant fashion.
The first step was to eliminate redundancy from C and C++. In many ways, the C
language evolved into a collection of overlapping features, providing too many
ways to say the same thing, while in many cases not providing needed
features. C++, in an attempt to add “classes in C”, merely added more
redundancy while retaining many of the inherent problems of C.
A major problem with C and C++ is the amount of context you need to
understand another programmer’s code: you have to read all related header
files, all related #defines, and all related typedefs before you can even begin
to analyze a program. In essence, programming with #defines and typedefs
results in every programmer inventing a new programming language that’s
incomprehensible to anybody other than its creator, thus defeating the goals of
good programming practices.
In Java, you obtain the effects of #define by using constants. You obtain the
effects of typedef by declaring classes—after all, a class effectively declares a
new type. You don’t need header files because the Java compiler compiles class
definitions into a binary form that retains all the type information through to
link time.
The following code fragment declares a class called Rectangle that uses
objects of the Point class as instance variables.
class Rectangle extends Object {
Point lowerLeft;
Point upperRight;
// methods to access the instance variables
}
2.2.3 No Enums
Java has no enum types. You can obtain something similar to enum by declaring
a class whose only raison d’etre is to hold constants. You could use this feature
something like this:
class Direction extends Object {
public static final int North = 1;
public static final int South = 2;
public static final int East = 3;
public static final int West = 4;
}
You can now refer to, say, the South constant using the notation
Direction.South.
Using the class-to-contain-constants technique in Java, you can use the same
names in different classes, because those names are qualified by the name of
the containing class. From our example just above, you might wish to create
another class called CompassRose:
class CompassRose extends Object {
public static final int North = 1;
public static final int NorthEast = 2;
public static final int East = 3;
public static final int SouthEast = 4;
public static final int South = 5;
public static final int SouthWest = 6;
public static final int West = 7;
public static final int NorthWest = 8;
}
If the x and y instance variables are private to this class, the only means to
access them is via the public methods of the class. Here’s how you’d use
objects of the Point class from within, say, an object of the Rectangle class:
class Rectangle extends Object {
Point lowerLeft;
Point upperRight;
It’s not to say that functions and procedures are inherently wrong. But given
classes and methods, we’re now down to only one way to express a given task.
By eliminating functions, your job as a programmer is immensely simplified:
you work only with classes and their methods.
int myInt;
double myFloat = 3.14159;
myInt = myFloat;
2.3 Summary
To sum up this chapter, Java is:
• Simple—the number of language constructs you need to understand to get
your job done is minimal.
• Familiar—Java looks like C and C++ while discarding the overwhelming
complexities of those languages.
Now that you’ve seen how Java was simplified by removal of features from its
predecessors, read the next chapter for a discussion on the object-oriented
features of Java.
32
3
In the distributed client-server world, you now have the potential for objects to
be created in one place, passed around networks, and stored elsewhere,
possibly in databases, to be retrieved for future work.
Java meets these requirements nicely, and adds considerable run-time support
to make your software development job easier.
What are objects? They’re software programming models. In your everyday life,
you’re surrounded by objects: cars, coffee machines, ducks, trees, and so on.
Software applications contain objects: buttons on user interfaces, spreadsheets
You drive your car to your office, where you track your stock portfolio. In your
daily interactions with the stock markets, a stock can be modelled by an object.
A stock has state (daily high, daily low, open price, close price, earnings per
share, relative strength), and behavior (changes value, performs splits, has
dividends).
After watching your stock decline in price, you repair to the cafe to console
yourself with a cup of good hot coffee. The espresso machine can be modelled as
an object. It has state (water temperature, amount of coffee in the hopper) and
it has behavior (emits steam, makes noise, and brews a perfect cup of java).
Method
Instance
Variables
Method
3.3.1 Classes
A class is a software construct that defines the data (state) and methods
(behavior) of the specific concrete objects that are subsequently constructed
from that class. In Java terminology, a class is built out of members, which are
either fields or methods. Fields are the data for the class. Methods are the
sequences of statements that operate on the data. Fields are normally specific
to an object—that is, every object constructed from the class definition will
have its own copy of the field. Such fields are known as instance variables.
Similarly, methods are also normally declared to operate on the instance
variables of the class, and are thus known as instance methods.
A class in and of itself is not an object. A class is like a blueprint that defines
how an object will look and behave when the object is created or instantiated
from the specification declared by the class. You obtain concrete objects by
instantiating a previously defined class. You can instantiate many objects from
one class definition, just as you can construct many houses all the same* from a
single architect’s drawing. Here’s the basic declaration of a very simple class
called Point
class Point extends Object {
public double x; /* instance variable */
public double y; /* instance variable */
}
Now, you can access the variables of this Point object by referring to the names
of the variables, qualified with the name of the object:
myPoint.x = 10.0;
myPoint.y = 25.7;
3.3.3 Constructors
When you declare a class in Java, you can declare optional constructors that
perform initialization when you instantiate objects from that class. You can also
declare an optional finalizer, discussed later. Let’s go back to our Point class
from before:
class Point extends Object {
public double x; /* instance variable */
public double y; /* instance variable */
This example is a variation on the Point class from before. Now, when you
wish to create and initialize Point objects, you can get them initialized to their
default values, or you can initialize them to specific values:
Point lowerLeft;
Point upperRight;
The specific constructor that’s used when creating a new Point object is
determined from the type and number of parameters in the new invocation.
In the example above, the constructors are simply conveniences for the Point
class. Situations arise, however, where constructors are necessary, especially in
cases where the object being instantiated must itself instantiate other objects.
Let’s illustrate one of those situations by declaring a Rectangle class that uses
two Point objects to define its bounds:
class Rectangle extends Object {
private Point lowerLeft;
private Point upperRight;
Rectangle() {
lowerLeft = new Point();
upperRight = new Point();
}
. . .
instance methods appear in here
. . .
}
Method
Method
Method
Instance
Variables
Method
Message
Method
Method
Method
Instance
Variables
Method
If an object wants another object to do some work on its behalf, then in the
parlance of object-oriented programming, the first object sends a message to the
second object. In response, the second object selects the appropriate method to
invoke. Java method invocations look similar to functions in C and C++.
These method declarations provide the flavor of how the Point class provides
access to its variables from the outside world. Another object that wants to
manipulate the instance variables of Point objects must now do so via the
accessor methods:
Point myPoint; // declares a variable to refer to a Point object
3.3.5 Finalizers
You can also declare an optional finalizer that will perform necessary teardown
actions when the garbage collector is about to free an object. This code
fragment illustrates a finalize method in a class.
This finalize method will be invoked when the object is about to be garbage
collected, which means that the object must shut itself down in an orderly
fashion. In the particular code fragment above, the finalize method merely
closes an I/O file stream that was used by the object, to ensure that the file
descriptor for the stream is closed.
3.3.6 Subclasses
Subclasses are the mechanism by which new and enhanced objects can be
defined in terms of existing objects. One example: a zebra is a horse with
stripes. If you wish to create a zebra object, you notice that a zebra is kind of
like a horse, only with stripes. In object-oriented terms, you’d create a new
class called Zebra, which is a subclass of the Horse class. In Java language
terms, you’d do something like this:
class Zebra extends Horse {
Your new instance variables and new methods go here
}
The definition of Horse, wherever it is, would define all the methods to
describe the behavior of a horse: eat, neigh, trot, gallop, buck, and so on. The
only method you need to override is the method for drawing the hide. You
gain the benefit of already written code that does all the work—you don’t have
to re-invent the wheel, or in this case, the hoof. The extends keyword tells the
Java compiler that Zebra is a subclass of Horse. Zebra is said to be a derived
class—it’s derived from Horse, which is called a superclass.
Notice that ThreePoint adds a new instance variable for the z coordinate of
the point. The x and y instance variables are inherited from the original Point
class, so there’s no need to declare them in ThreePoint. However, notice we
had to make Point’s instance variables protected instead of private as in
the previous examples. Had we left Point’s instance variables private, even
its subclasses would be unable to access them, and the compilation would fail.
Subclasses enable you to use existing code that’s already been developed and,
much more important, tested, for a more generic case. You override the parts of
the class you need for your specific behavior. Thus, subclasses gain you reuse
All classes in Java ultimately inherit from Object. Object is the most general
of all the classes. New classes that you declare add functionality to their
superclasses. The further down the class hierarchy you go—that is, the further
you get from Object—the more specialized your classes become.
Then the Properties class subclasses HashTable in turn, inheriting all the
variables and behavior of its class hierarchy. In a similar manner, Stack and
ObserverList are subclasses of Vector, which in turn is a subclass of
Object. The power of the object-oriented methodology is apparent—none of
the subclasses needed to re-implement the basic functionality of their
superclasses, but needed only add their own specialized behavior.
Object
Vector
BitSet
Enumerator
Dictionary Vector
Hashtable Hashtable
Observable
Entry Enumerator
Hashtable
Stack ObserverList
Properties
However, the above diagram points out the minor weakness with the single-
inheritance model. Notice that there are two different kinds of enumerator
classes in the picture, both of which inherit from Object. An enumerator class
Whereas a class can inherit from only one superclass, a class can implement as
many interfaces as it chooses to. Using the examples from the previous
discussion, the HashTableEnumerator and VectorEnumerator classes both
implement an Enumeration interface that’s specific to the characteristics of
the HashTable and Vector classes. When you define a new collection
class—a Queue class, for instance—you’ll also probably define a
QueueEnumerator class that implements the Enumeration interface.
Cloneable Enumeration
Object Cloneable
Vector
BitSet
Enumerator
Dictionary Vector
Hashtable Hashtable
Observable
Entry Enumerator
Hashtable
Enumeration
Cloneable
Stack ObserverList
Properties
In this illustration, interfaces are represented by rectangles. You see that the
Cloneable interface is implemented by multiple classes. In addition, the
HashtableEnumerator and the VectorEnumerator classes both implement
implement them. When inheriting from classes (in languages such as C++), the
implementation of inherited classes is also inherited, so more code can be
reused when compared to the amount of code re-use in multiply-inherited
interfaces. For this reason, inheriting from interfaces provides a reasonable
alternative to multiple inheritance, but this practice should not be seen as a
substitute for the more powerful but often confusing practice of inheriting
from multiple classes.
The fourth access level doesn’t have a name—it’s often called “friendly” and is
the access level you obtain if you don’t specify otherwise. The “friendly”
access level indicates that the class’s members are accessible to all objects
within the same package, but inaccessible to objects outside the package.
Packages, a useful tool for grouping together related collections of classes and
interfaces, are discussed below.
3.3.9 Packages
Java packages are collections of classes and interfaces that are related to each
other in some useful way. Such classes need to be able to access each other’s
instance variables and methods directly. A geometry package consisting of
Point and Rectangle classes, for instance, might well be easier and cleaner
to implement—as well as more efficient—if the Point’s instance variables
To declare class variables and class methods in Java programs, you declare
them static. This short code fragment illustrates the declaration of class
variables:
class Rectangle extends Object {
static final int version = 2;
static final int revision = 0;
}
The Rectangle class declares two static variables to define the version and
revision level of this class. Now, every instance of Rectangle you create from
this class will share these same variables. Notice they’re also defined as final
because you want them to be constants.
Class methods are common to an entire class. When would you use class
methods? Usually, when you have behavior that’s common to every object of a
class. For example, suppose you have a Window class. A useful item of
information you can ask the class is the current number of currently open
windows. This information is shared by every instance of Window and it is
In general, class methods can operate only on class variables. Class methods
can’t access instance variables, nor can they invoke instance methods. Like
class variables, you declare class methods by defining them as static.
We say, “in general”, because you could pass an object reference to a class
method, and the class method could then operate on the object’s public
instance variables, and invoke the object’s instance methods via the reference.
However, you’re usually better off doing only class-like operations at the class
level, and doing object-like operations at the object level.
This all sounds wonderfully, well, abstract, so why would you need an abstract
superclass? Let’s look at a concrete example, no pun intended. Let’s suppose
you’re going to a restaurant for dinner, and you decide that tonight you want
to eat fish. Well, fish is somewhat abstract—you generally wouldn’t just order
fish; the waiter is highly likely to ask you what specific kind of fish you want.
When you actually get to the restaurant, you will find out what kind of fish
they have, and order a specific fish, say, sturgeon, or salmon, or opakapaka.
In the world of objects, an abstract class is like generic fish—the abstract class
defines generic state and generic behavior, but you’ll never see a real live
implementation of an abstract class. What you will see is a concrete subclass of
the abstract class, just as opakapaka is a specific (concrete) kind of fish.
Suppose you are creating a drawing application. The initial cut of your
application can draw rectangles, lines, circles, polygons, and so on.
Furthermore, you have a series of operations you can perform on the
shapes—move, reshape, rotate, fill color, and so on. You could make each of
these graphic shapes a separate class—you’d have a Rectangle class, a Line
At this point, you realize you can collect all the instance variables into a single
abstract superclass called Graphical, and implement most of the methods to
manipulate the variables in that abstract superclass. The skeleton of your
abstract superclass might look something like this:
abstract class Graphical extends Object {
protected Point lowerLeft; // lower left of bounding box
protected Point upperRight; // upper right of bounding box
. . .
more instance variables
. . .
public void setPosition(Point ll, Point ur) {
lowerLeft = ll;
upperRight = ur;
}
abstract void drawMyself(); // abstract method
}
Now, you can’t instantiate the Graphical class, because it’s declared
abstract. You can only instantiate a subclass of it. You would implement the
Rectangle class or the Circle class as a subclass of Graphical. Within
Rectangle, you’d provide a concrete implementation of the drawMySelf
method that draws a rectangle, because the definition of drawMySelf must by
necessity be unique to each shape inherited from the Graphical class. Let’s
see a small fragment of the Rectangle class declaration, where its
drawMySelf method operates in a somewhat PostScript’y fashion:
class Rectangle extends Graphical {
void drawMySelf() { // really does the drawing
moveTo(lowerLeft.x, lowerLeft.y);
lineTo(upperRight.x, lowerLeft.y);
lineTo(upperRight.x, upperRight.y)
lineTo(lowerLeft.x, upperRight.y);
. . .
and so on and so on
. . .
}
}
You can continue in this way adding new shapes that are subclasses of
Graphical, and most of the time, all you ever need to implement is the
methods that are unique to the specific shape. You gain the benefit of re-using
all the code that was defined inside the abstract superclass.
3.4 Summary
This chapter has conveyed the essential aspects of Java as an object-oriented
language. To sum up:
• Classes define templates from which you instantiate (create) distinct concrete
objects.
• Instance variables hold the state of a specific object.
• Objects communicate by sending messages to each other. Objects respond to
messages by selecting a method to execute.
• Methods define the behavior of objects instantiated from a class. It is an
object’s methods that manipulate its instance variables. Unlike regular
procedural languages, classes in an object-oriented language may have
methods with the same names as other classes. A given object responds to a
message in ways determined by the nature of that object, providing
polymorphic behavior.
• Subclasses provide the means by which a new class can inherit instance
variables and methods from any already defined class. The newly declared
class can add new instance variables (extra state), can add new methods
(new behavior), or can override the methods of its superclass (different
behavior). Subclasses provide code reuse.
This chapter describes the ways in which Java has addressed the issues of
architecture neutrality, portability, and reliability.
50
4
One of the early examples of the bytecode approach was the UCSD P-System,
which was ported to a variety of eight-bit architectures in the middle 1970s and
early 1980s and enjoyed widespread popularity during the heyday of eight-bit
machines. Coming up to the present day, current architectures have the power
to support the bytecode approach for distributed software. Java bytecodes are
designed to be easy to interpret on any machine, or to dynamically translate
into native machine code if required by performance demands.
With the PC market (through Windows 95 and Windows NT) diversifying onto
many CPU architectures, and Apple moving full steam from the 68000 to the
PowerPC, production of software to run on all platforms becomes almost
impossible until now. Using Java, coupled with the Abstract Window Toolkit,
the same version of your application can run on all platforms.
4.2 Portable
The primary benefit of the interpreted byte code approach is that compiled
Java language programs are portable to any system on which the Java
interpreter and run-time system have been implemented.
Java eliminates this issue by defining standard behavior that will apply to the
data types across all platforms. Java specifies the sizes of all its primitive data
types and the behavior of arithmetic on them. Here are the data types:
The data types and sizes described above are standard across all
implementations of Java. These choices are reasonable given current
microprocessor architectures because essentially all central processor
architectures in use today share these characteristics. That is, most modern
processors can support two’s-complement arithmetic in 8-bit to 64-bit integer
formats, and most modern processors support single- and double-precision
floating point.
4.3 Robust
Java is intended for developing software that must be robust, highly reliable,
and secure, in a variety of ways. There’s strong emphasis on early checking for
possible problems, as well as later dynamic (run-time) checking, to eliminate
error-prone situations.
One of the advantages of a strongly typed language (like C++) is that it allows
extensive compile-time checking, so bugs can be found early. Unfortunately,
C++ inherits a number of loopholes in its compile-time checking from C.
Unfortunately, C++ and C are relatively lax, most notably in the area of method
or function declarations. Java imposes much more stringent requirements on
the developer: Java requires explicit declarations and does not support C-style
implicit declarations.
Many of the stringent compile-time checks at the Java compiler level are
carried over to the run time, both to check consistency at run time, and to
provide greater flexibility. The linker understands the type system and repeats
many of the type checks done by the compiler, to guard against version
mismatch problems.
The single biggest difference between Java and C or C++ is that Java’s memory
model eliminates the possibility of overwriting memory and corrupting data.
Instead of pointer arithmetic, Java has true arrays and strings, which means
that the interpreter can check array and string indexes. In addition, a
programmer can’t write code that turns an arbitrary integer into an object
reference by casting.
4.4 Summary
Java—an architecture-neutral and portable programming language—provides an
attractive and simple solution to the problem of distributing your applications
across heterogeneous network-based computing platforms. In addition, the
simplicity and robustness of the underlying Java language results in higher
quality, reliable applications in which users can have a high level of confidence.
The next chapter contains a brief discussion of Java’s interpreted
implementation.
Better methods of fast and fearless prototyping and development are needed.
The Java language environment is one of those better ways, because it’s
interpreted and dynamic.
The Java language virtual machine is a strictly defined virtual machine for
which an interpreter must be available for each hardware architecture and
operating system on which you wish to run Java language applications. Once
* One of the ancestors of the virtual machine concept was the UCSD P System, developed by Kenneth Bowles
at the University of California at San Diego in the late 1970s.
56
5
you have the Java language interpreter and run-time support available on a
given hardware and operating system platform, you can run any Java language
application from anywhere, always assuming the specific Java language
application is written in a portable manner.
The notion of a separate “link” phase after compilation is pretty well absent
from the Java environment. Linking, which is actually the process of loading
new classes by the Class Loader, is a more incremental and lightweight process.
The concomitant speedup in your development cycle means that your
development process can be much more rapid and exploratory, and because of
the robust nature of the Java language and run-time system, you will catch
bugs at a much earlier phase of the cycle.
Finally, the storage layout of objects is not determined by the compiler. The
layout of objects in memory is deferred to run time and determined by the
interpreter. Updated classes with new instance variables or methods can be
linked in without affecting existing code.
At the small expense of a name lookup the first time any name is encountered,
the Java language eliminates the fragile superclass problem. Java programmers
can use object-oriented programming techniques in a much more
straightforward fashion without the constant recompilation burden
engendered by C++. Libraries can freely add new methods and instance
variables without any effect on their clients. Your life as a programmer is
simpler.
5.2 Summary
The interpreted and dynamic nature of Java provides several benefits:
• The interpreted environment enables fast prototyping without waiting for
the traditional compile and link cycle,
• The environment is dynamically extensible, whereby classes are loaded on
the fly as required,
• The fragile superclass problem that plagues C++ developers is eliminated
because of deferral of memory layout decisions to run time.
Security commands a high premium in the growing use of the Internet for
products and services ranging from electronic distribution of software and
multimedia content, to “digital cash”. The area of security with which we’re
concerned here is how the Java compiler and run-time system restrict
application programmers from creating subversive code.
The Java language compiler and run-time system implement several layers of
defense against potentially incorrect code. The environment starts with the
assumption that nothing is to be trusted, and proceeds accordingly. The next
few sections discuss the Java security models in greater detail.
Secondly, Java does not have “pointers” in the traditional C and C++ sense of
memory cells that contain the addresses of other memory cells.The Java
compiled code references memory via symbolic “handles” that are resolved to
real memory addresses at run time by the Java interpreter. Java programmers
60
6
can’t forge pointers to memory, because the memory allocation and referencing
model is completely opaque to the programmer and controlled entirely by the
underlying run-time platform.
Very late binding of structures to memory means that programmers can’t infer
the physical memory layout of a class by looking at its declaration. By
removing the C and C++ memory layout and pointer models, the Java
language has eliminated the programmer’s ability to get behind the scenes and
either forge or otherwise manufacture pointers to memory. These features must
be viewed as positive benefits rather than a restriction on the programmer,
because they ultimately lead to more reliable and secure applications.
When a class is imported from across the network it is placed into the private
name space associated with its origin. When a class references another class, it
is first looked for in the name space for the local system (built-in classes), then
in the name space of the referencing class. There is no way that an imported
class can “spoof” a built-in class. Built-in classes can never accidentally
reference classes in imported name spaces—they can only reference such
classes explicitly. Similarly, classes imported from different places are
separated from each other.
The tests range from simple verification that the format of a code fragment is
correct, to passing each code fragment through a simple theorem prover to
establish that it plays by the rules:
• it doesn’t forge pointers,
• it doesn’t violate access restrictions,
• it accesses objects as what they are (for example, InputStream objects are
always used as InputStreams and never as anything else).
Security in Java 62
6
Bytecodes
move through Class Loader
network or Bytecode Verifier
file system
Java
Source
Java
Just in Time
Virtual Machine
Compiler
Java
Compiler
Operating System
Java
Hardware
ByteCodes
The illustration shows the flow of data and control from Java language source
code through the Java compiler, to the class loader and bytecode verifier and
hence on to the Java virtual machine, which contains the interpreter and
runtime system. The important issue is that the Java class loader and the
bytecode verifier make no assumptions about the primary source of the
bytecode stream—the code may have come from the local system, or it may
have travelled halfway around the planet. The bytecode verifier acts as a sort
of gatekeeper: it ensures that code passed to the Java interpreter is in a fit state
to be executed and can run without fear of breaking the Java interpreter.
Imported code is not allowed to execute by any means until after it has passed
the verifier’s tests. Once the verifier is done, a number of important properties
are known:
• There are no operand stack overflows or underflows
While all this checking appears excruciatingly detailed, by the time the
bytecode verifier has done its work, the Java interpreter can proceed, knowing
that the code will run securely. Knowing these properties makes the Java
interpreter much faster, because it doesn’t have to check anything. There are no
operand type checks and no stack overflow checks. The interpreter can thus
function at full speed without compromising reliability.
6.5 Summary
Java is secure to survive in the network-based environment. The architecture-
neutral and portable aspects of the Java language make it the ideal development
language to meet the challenges of distributing dynamically extensible software
across networks.
Security in Java 64
6
Unfortunately, writing programs that deal with many things happening at once
can be much more difficult than writing in the conventional single-threaded C
and C++ style. You can write multithreaded applications in languages such as
C and C++, but the level of difficulty goes up by orders of magnitude, and
even then there are no assurances that vendors’ libraries are thread-safe.
The term thread-safe means that a given library function is implemented in such
a manner that it can be executed by multiple concurrent threads of execution.
The major problem with explicitly programmed thread support is that you can
never be quite sure you have acquired the locks you need and released them
again at the right time. If you return from a method prematurely, for instance,
or if an exception is raised, for another instance, your lock has not been
released; deadlock is the usual result.
66
7
downloading a text file from a server, multithreading is the way to obtain fast,
lightweight concurrency within a single process space. Threads are sometimes
also called lightweight processes or execution contexts.
Threads are an essential keystone of Java. The Java library provides a Thread
class that supports a rich collection of methods to start a thread, run a thread,
stop a thread, and check on a thread’s status.
Java’s threads are pre-emptive, and depending on platform on which the Java
interpreter executes, threads can also be time-sliced. On systems that don’t
support time-slicing, once a thread has started, the only way it will relinquish
control of the processor is if another thread of a higher priority takes control of
the processor. If your applications are likely to be compute-intensive, you
might consider how to give up control periodically by using the yield()
method to give other threads a chance to run; doing so will ensure better
interactive response for graphical applications.
Here are a couple of code fragments from the sorting demonstration in the
HotJava web browser. The main points of interest are the two methods stop
and startSort, which share a common variable called kicker (it kicks off
the sort thread):
public synchronized void stop() {
if (kicker != null) {
kicker.stop();
If you’re writing Java applications, you should take care to implement your
classes and methods so they’re thread-safe, in the same way that Java run-time
libraries are thread-safe. If you wish your objects to be thread-safe, any
methods that may change the values of instance variables should be declared
synchronized. This ensures that only one method can change the state of an
object at any time. Java monitors are re-entrant: a method can acquire the same
monitor more than once, and everything will still work.
Multithreading 68
7
8.1 Performance
Java has been ported to and run on a variety of hardware platforms executing
a variety of operating system software. Test measurement of some simple Java
programs on current high-end computer systems such as workstations and
high-performance personal computers show results roughly as follows:
Thus, we see that creating a new object requires approximately 8.4 µsec,
creating a new class containing several methods consumes about 11 µsec, and
invoking a method on an object requires roughly 1.7 µsec.
While these performance numbers for interpreted bytecodes are usually more
than adequate to run interactive graphical end-user applications, situations
may arise where higher performance is required. In such cases, Java bytecodes
can be translated on the fly (at run time) into machine code for the particular
CPU on which the application is executing. This process is performed by the
70
8
Just In Time (JIT) compiler. For those accustomed to the normal design of a
compiler and dynamic loader, the Just In Time compiler is somewhat like
putting the final machine code generator in the dynamic loader.
The bytecode format was designed with generating machine codes in mind, so
the actual process of generating machine code is generally simple. Reasonably
good code is produced: it does automatic register allocation and the compiler
does some optimization when it produces the bytecodes. Performance of
bytecodes converted to machine code is roughly the same as native C or C++.
Languages at the level of the Shells and TCL, for example, are fully interpreted
high-level languages. They deal with “objects” (in the sense they can be said to
deal with objects at all) at the system level, where their objects are files and
processes rather than data structures. Some of these languages are suitable for
very fast prototyping—you can develop your ideas quickly, try out new
approaches, and discard non-working approaches without investing enormous
amounts of time in the process. Scripting languages are also highly portable.
Their primary drawback is performance; they are generally much slower than
either native machine code or interpreted bytecodes. This tradeoff may well be
reasonable if the run time of such a program is reasonably short and you use
the program infrequently.
In the intermediate ground come languages like Perl, that share many
characteristics in common with Java. Perl’s ongoing evolution has led to the
adoption of object-oriented features, security features, and it exhibits many
features in common with Java, such as robustness, dynamic behavior,
architecture neutrality, and so on.
At the lowest level are compiled languages such as C and C++, in which you
can develop large-scale programming projects that will deliver high
performance. The high performance comes at a cost, however. Drawbacks
include the high cost of debugging unreliable memory management systems
and the use of multithreading capabilities that are difficult to implement and
Prospective adopters of the Java language need to examine where the Java
language fits into the firmament of other languages. Here is a basic comparison
chart illustrating the attributes of the Java language—simple, object-oriented,
threaded, and so on—as described in the earlier parts of this paper.
Simple
Object
Oriented
Robust
Secure
Interpreted
Dynamic
Portable
Neutral
Threads
Garbage
Collection
Exceptions
e
anc High Medium Low Medium Low High High
rm
Perfo
Feature exists
From the diagram above, you see that the Java language has a wealth of
attributes that can be highly beneficial to a wide variety of developers. You can
see that Java, Perl, and SmallTalk are comparable programming environments
offering the richest set of capabilities for software application developers.
Another reason commonly given that languages like Lisp, TCL, and SmallTalk
are good for prototyping is that they don’t require you to pin down decisions
early on—these languages are semantically rich.
Java has exactly the opposite property: it forces you to make explicit choices.
Along with these choices come a lot of assistance—you can write method
invocations and, if you get something wrong, you get told about it at compile
time. You don’t have to worry about method invocation error.
8.4 Summary
From the discussion above, you can see that the Java language provides high
performance, while its interpreted nature makes it the ideal development
platform for fast and fearless prototyping. From the previous chapters, you’ve
seen that the Java language is extremely simple and object oriented. The
language is secure to survive in the network-based environment. The
architecture-neutral and portable aspects of the Java language make it the ideal
development language to meet the challenges of distributing dynamically
extensible software across networks.
The complete Java system includes several libraries of utility classes and
methods of use to developers in creating multi-platform applications. Very
briefly, these libraries are:
This picture illustrates the classes in java.lang, excluding all the exception and
error classes.
76
9
Object
Throwable
Boolean
Thread
Character Group
Class Thread
Math Security
Manager System
Number
Integer Double
Long Float
Object File
Descriptor
File
Stream
Tokenizer
Random
DataInput AccessFile DataOutput
Input Output
Stream Stream
ByteArray ByteArray
InputStream OutputStream
Piped File
InputStream OutputStream
File Piped
InputStream OutputStream
Sequence Filter
InputStream OutputStream
StringBuffer
InputStream
Filter
InputStream Buffered
OutputStream
Data
OutputStream
Bufferered Print
InputStream Stream
Data
InputStream
LineNumber
InputStream
Pushback
InputStream
Note that the grayed out boxes with DataInput and DataOutput represent
interfaces, not classes. Any new I/O class that subclasses one of the other
classes can implement the appropriate interface if it needs to.
Object
BitSet
String
Date Tokenizer Vector
Dictionary Observable
Random
Hashtable
Enumerator
Hashtable Stack Observer
Entry List
Hashtable
Properties
FileDialog
GridLayout
Dialog
GridBag
LayoutInfo
GridBag Component
Window Frame
Layout
Flow
Layout
Container Panel
Card
Layout
Applet
Border
Layout
Object
MenuBar
CheckBox
Group
Menu
Color Component
Event GridBag
Constraints
Font
Image Point
Menu CheckBox
FontMetrics MenuItem
Insets
Polygon
MediaEntry
Rectangle
Media
Image Tracker
MediaEntry Toolkit
HotJava includes many innovative features and capabilities above and beyond
the first generation of static Web browsers. HotJava is extensible. Its foremost
feature is its ability to download Java programs (applets) from anywhere, even
across networks, and execute them on the user’s machine. HotJava builds on
the network-browsing techniques established by Mosaic and other Web
browsers and expands them by adding dynamic behavior that transforms static
documents into dynamic applications.
82
10
HotJava goes far beyond the first generation of statically-oriented Web
browsers and brings a much needed measure of interactivity to the concept of
the Web browser. It transforms the existing static data display of first
generation Web browsers into a new and dynamic viewing system for
hypertext, which is described below. HotJava enables creation and display of
animation-oriented applications. World-Wide Web content developers can have
their applications distributed across the Internet with the click of a button on
the user’s client computer.
Java has been adopted enthusiastically by the internet community and Java
capabilities have appeared in many Internet-related products like Web
browsers and other client-server applications.
The concept of hypertext is by no means new, but its realization has spanned
decades. The idea behind hypertext was described in an essay by Vannevar
Bush in 1945, and evangelized by Theodore (Ted) Nelson in the 1960s and
1970s. Although Apple Computer’s HyperCard product for Macintosh
provided an early if somewhat primitive implementation, the real power of
hypertext comes from the ability to create inter-document links across multiple
host computers on the network. The first practical if small implementation of a
network-based hypertext system was created by Tim Berners-Lee at CERN,
using the NEXTSTEP development environment to create what would blossom
into HTML (HyperText Markup Language), HTTP (HyperText Transport
Protocol), and the WWW (World-Wide Web, or W3).
Web browsers combine the functions of fetching data with figuring out what
the data is and displaying it if possible. One of the most prevalent file formats
that browsers deal with is HyperText Markup Language, or HTML— a markup
language that embeds simple text-formatting commands within text to be
formatted. The main key to the hypertext concept is HTML’s use of links to
other HTML pages either on the same host or elsewhere on the Internet.
Display
Text
and
Images
Fetch Click
Data Link
Decode
URL
This illustration depicts roughly the “interactive” flow of control in the first-
generation Web browsers. You can see that it’s not really highly
interactive—it’s just a fancy data fetching and display utility with fixed
hypertext links. It does not dynamically handle new data types, protocols, or
behaviors.
The primary problem with the first-generation web browsers is that they’re
built in a monolithic fashion with their awareness of every possible type of
data, protocol, and behavior hard-wired in order for them to navigate the Web.
This means that every time a new data type, protocol, or behavior is invented,
these browsers must be upgraded to be cognizant of the new situation. From
the viewpoint of end users, this is an untenable position to be in. Users must
continually be aware of what protocols exist, which browsers deal with those
protocols, and which versions of which browsers are compatible with each
other. Given the growth of the Internet, this situation is clearly out of control.
Furthermore, HotJava provides the means for users to access these applications
in a new way. Software migrates transparently across the network as it’s
needed. You don’t have to “install” software—it comes across the network as
you need it—perhaps after asking you to pay for it. Content developers for the
World-Wide Web don’t have to worry about whether or not some special piece
of software is installed in a user’s system—it just gets there automatically. This
transparent acquiring of applications frees content developers from the
boundaries of the fixed media types such as images and text and lets them do
whatever they’d like.
new1
smtp
nntp
url
ftp
gif
new2
html
new3
http
HOTJAVA
In a book or HTML document, the author has to be content with these static
illustrations. With HotJava the author can enable the reader to click on the
illustrations and see the algorithms animate:
Using these dynamic facilities, content providers can define new types of data
and behavior that meet the needs of their specific audiences, rather than being
bound by a fixed set of objects.
User asks
for object
request
Object
reply
Browser
doesn’t
Time
understand
object type request Java
code to
support
object
reply
Object
Displayed
Products from
Vendor A
VATP
Server
Proprietary
Protocol
Web
Browser
?
With HotJava as a base, vendors can produce and sell exactly the piece that is
their added value, and integrate smoothly with other vendors, creating a final
result that is seamless and very convenient for the end user.
User Population
Ability to innovate
Time
Within a community that uses HotJava, individuals can experiment with new
facilities while at the same time preserving compatibility and interoperability.
Data can be published in new formats and distributed using new protocols and
the implementations of these will be automatically and safely installed. There
is no upgrade problem.
One need not be inventing new things to need these facilities. Almost all
organizations need to be able to adapt to changing requirements. The HotJava
browser’s flexibility can greatly aid that. As new protocols and data types
become important, they can be transparently incorporated.
That’s all there is to Mosaic. It’s essentially very simple. But despite this
apparent simplicity, the Mosaic program is actually huge since it must contain
specialized handlers for all of these data types. It’s bundled together into one
big monolithic lump.
In contrast, HotJava is very small, because all of the protocol and data handlers
are brought in from the outside. For example, when it calls the protocol
handler, instead of having a table that has a fixed list of protocols that it
understands, HotJava instead uses this type string to derive a Java language
class name. The protocol handler for this type is dynamically linked in if it is
missing. They can be linked in from the local system, or they can be linked in
from definitions stored on the host where the URL was found, or anywhere
else on the net that HotJava suspects might be a good place to look. In a similar
fashion, HotJava can dynamically locate and load the code to handle different
types of data objects and different ways of viewing them.
10.4 Security
Network security is of paramount importance to Internet users, especially with
the exponential growth of Internet commerce. Network-based applications
must be able to defend themselves against a veritable gallimaufry of network
viruses, worms, Trojan horses, and other forms of intruders. This section
discusses the layers of defense provided by Java, the Java run-time system, and
the higher-level protocols of HotJava itself.
Sun Microsystems
http://java.sun.com/progGuide/index.html
94
11
An introduction to Smalltalk.