HostedDB - Dedicated UNIX Servers

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


And, of course, C and C++’s beloved pointer is gone. According to the Java group, pointers are one of the primary features that introduce bugs into programs, and few programmers would disagree. By getting rid of structures and encapsulating arrays as objects, Java attempts to eliminate the original reasoning behind pointers. Some hard-core C/C++ programmers will have a hard time swallowing the absence of pointers. In some ways, learning about pointers was considered a rite of passage for programmers, and if you use them correctly, they are very powerful. Used incorrectly, however, you are guaranteed long nights of debugging code. Obviously, pointers are a massively weak link in a portable, secure environment, and the Java group made the right decision in eliminating them. By encapsulating the use of pointers into objects, they made sure that writing for Java will produce robust, efficient code much less prone to difficult bugs, memory leaks, and corruption. Especially in a secure environment, hanging pointers are a disaster waiting to happen.

By building Java from the ground up as an object-oriented language, programmers deal with only one thing—the class. After learning how to handle one class, they can handle all classes. In addition, the many features of the Java environment are encapsulated within classes, providing a rich set of predefined classes for use by programmers. With only a few lines of code, programmers can use advanced features of the Java architecture with a greater understanding of the process than many visual programming environments evoke by hiding complex APIs and code generation behind automated tools.

Memory Management and Threads

Perhaps the greatest benefit of the Java language is its automatic memory management and thread controls. In C and C++, memory must be explicitly managed by using free, malloc, and a host of other memory management standard libraries. Knowing when to allocate, free, and generally keep track of all your memory usage is difficult. Using threads in C and C++ meant using a class library for all thread control. Although threads still require the use of classes, Java also includes thread synchronization at the language level.

Java has taken over the role of the memory manager. Once an object is created, the Java runtime system oversees the object until it is no longer needed by keeping track of all references to an object. When Java detects there are no more references to an object, it places the object on the stack for garbage collection. To keep performance loss at a minimum yet still provide the benefits of automatic garbage collection, Java runs this garbage collection utility as a background process (or low priority thread). By doing so, it stays out of the way until there is either a sufficient pause in the execution of foreground threads to run, or the system explicitly requires the use of memory that might be available but is taken up by defunct classes.

The background memory manager is a good example of how multithreading can increase the relative performance in the Java environment. Because of its importance, multithreading has been incorporated at the language level by allowing for thread synchronization. The Java language supports the synchronized modifier for methods, indicating the order in which threads should be run. In addition, the threadsafe modifier, used in the definition of methods, gives the environment clues about how methods interact with instance variables to make sure that no two threads conflict in trying to modify data.

Java’s memory management and thread support are examples of how both a reduction of and a minor addition to the syntax produce a simpler language for the programmer to use. By getting rid of pointers, the use of malloc and free, and incorporating these tasks into the Java environment, the programmer is free to work on the actual programming job, not on mundane housekeeping chores that typically occupy the most time when fixing bugs. At the same time, Java can still boast impressive performance for a portable, interpreted system. By balancing the addition of thread synchronization between the language and class level, Java takes advantage of modern operating systems to further boost application performance without overburdening the language or environment with unnecessary elements.

The Java language is fine tuned for its environment—high-performance distributed computing on heterogeneous systems—essentially the Internet. Although you might not consider desktop systems high performance, what you now have sitting on your desk is quite advanced compared to even four years ago when Java was conceived. In addition, all of today’s modern operating systems include advanced features such as built-in networking, a true multitasking, multithreading capability that was found only in expensive Unix workstations a few years ago. By providing a familiar, simple, object-oriented language, Java enables the programmer to concentrate on the work at hand—developing advanced content for distribution over a variety of hardware and software platforms.

The Java Architecture

The Java architecture, as discussed before, provides a portable, robust, high-performance environment for development. Java provides portability by compiling bytecodes for the JVM that are then interpreted on each platform by the runtime environment. Java also provides stringent compile and runtime checking and automatic memory management in order to ensure solid code. Additionally, strong security features protect systems against ill-behaved programs (whether unintentional or intentional). Java is also a highly dynamic system, able to load code when needed from a machine on a desk across the room or across the continent.


Previous Table of Contents Next