HostedDB - Dedicated UNIX Servers

-->
Internet Security Professional Reference:Java Security
Previous Table of Contents Next


Java’s Robust Features

The fragile superclass problem is a perfect example of the problems faced in attempting to develop a robust development and runtime environment and the solution that Java implements. In addition to the fragile superclass problem, Java has many other features that provide a reliable environment for running distributed applications, including automatic memory management and strict compile-time and runtime checking. Java attempts to reduce application failure by both stringent checking and the reduction of crash-prone elements of a language.

In addition to solving the problem of the fragile superclass, automatic memory management and the elimination of pointers and unbound arrays create an environment where the programmer is less likely to write bad code in the first place. Most destructive errors occur when a program writes to an incorrect memory address. When a programmer must address memory in C++, he does so by using pointers—essentially variables that hold the address of the memory range in use. To address memory, a programmer takes the pointer value, and, by using pointer arithmetic (essentially adding or subtracting the number of memory blocks to move), calculates where to move next. Of course, if there are any mistakes in the pointer arithmetic, the pointer can go anywhere, even into essential areas of memory such as the operating system.

Today’s modern operating systems are typically protected against such occurrences. Programs with runaway pointers, however, are similar to small children with guns—they are likely to harm themselves and anyone around them who has not taken cover. Java eliminates the pointer from the programmer’s repertoire and encapsulates memory usage into finely tuned, robust classes that provide all the necessary functionality without the difficulty in managing and dangers in using pointers.

Besides eliminating language elements that are dangerous and difficult to use, Java adheres to strict compile time and runtime checking to ensure that all programs adhere to correct syntax and procedure. C++ is also considered a strong type-checking language, but its compatibility with C brings along with it situations in which such stringent requirements are not possible. Because Java is a new language, the compiler can check all syntax for errors strictly. This way, a programmer will discover errors before they have a chance to make it into running code.

The checking does not stop there, however. After the program has compiled correctly, the interpreter performs its own type checking to ensure that distribution, dynamic linking, or file corruption has not introduced errors into the code. Rather than assuming the code is correct, the linker makes sure that everything is consistent with the language and the code is internally consistent before execution. This is an important step because an application might pull in fragments from anywhere in the distributed environment. If not checked at runtime, there is no way to guarantee that the program will run.

Multithreading

A major element in the Java architecture is its inclusion of multithreading at every level. Multithreading begins at the syntactical level with synchronization modifiers included in the language. At the object level, the class libraries enable the creation of threaded applications by inheriting classes developed for this purpose. Finally, the Java runtime environment uses multithreading in areas such as background garbage collection to speed performance while retaining usability.

Multitasking is an operating system that can run more than one program at a time. Multithreading is an application that has more than one thread of execution at a time. Multitasking is having both Word and Excel running simultaneously, while multithreading is having Word spell-checking one document and printing another at the same time. The majority of PC systems (both Windows and MacOS), however, are cooperative multitasking, multithreading. Each program or thread must give up control for the others to have a chance; many times the software did not allow this. Preemptive methods, however, allocate each program a certain amount of time with the system and then pass it on. This ensures that each task or thread receives an equal share of time on the system. Multithreading works because the majority of programs require some amount of input from the user. Because humans are frequently slower than computers, while one task is stalled waiting for some input, other threads have time to carry out what they need to.

Multitasking and multithreading are probably considered two of the primary benefits in the new wave of operating systems being developed at the time of this writing. Although preemptive multitasking and multithreading have been around for some time at the workstation level, until recently, desktop systems provided little more than cooperative multitasking and no multithreading solutions.

New PC (and many old workstation) operating systems are preemptive—they control programs and give them each a slice of processing time according to their priority. Java takes advantage of this and enables applications written for it to be preemptive multithreading. In fact, programs running in the Java interpreter are automatically multithreading. The background garbage collector runs as a low priority thread, collecting unused memory from finished objects. By providing a multithreading system, Java overcomes many of the inherent difficulties in interpreted environments and provides the developer with the most advanced features available in today’s operating systems.


Previous Table of Contents Next