Java's three types of portability
Find out about the types of portability Java supports, and how Microsoft could undermine the technology by subverting the
one type that most threatens its hold on the desktop operating system market
By Mark Roulo, JavaWorld.com, 05/01/97
Java has generated a lot of excitement in the programming community because it promises
portable applications and applets. In fact, Java provides three distinct types of portability: source code portability, CPU architecture
portability, and OS/GUI portability. The fact that there are three distinct types of portability is critical, because only
one of these types is a threat to Microsoft. Microsoft can be expected to undermine that one type of portability while embracing
the other two -- all the while claiming to support Java. Understanding the three types of portability and how they work together
is critical to understanding the threat to Microsoft, and Microsoft's possible responses.
Before jumping into details on each of these three types of portability, though, let's review a few fundamental terms.
Defining some terms
The following terms are used in this article:
- Endianism
- Endianism refers to the storage order of bytes in a multibyte quantity in a given CPU. For example, the unsigned short 256
(decimal) requires two bytes of storage: a 0x01 and 0x00. These two bytes can be stored in either order:
0x01, 0x00 or 0x00, 0x01. Endianism determines the order in which the two bytes are stored. For practical purposes, endianism usually matters only
when CPUs of different endianism must share data.
- Java
- Java is several different technologies packaged together -- the Java programming language, the Java virtual machine (JVM),
and the class libraries associated with the language. This article discusses all of these aspects.
- Java virtual machine (JVM)
- The JVM is an imaginary CPU for which most Java compilers emit code. Support for this imaginary CPU is what allows Java programs
to run without being recompiled on different CPUs. Nothing in the Java programming language requires Java source code to be
compiled into code for the JVM instead of into native object code.
In fact, Asymetrix and Microsoft have announced Java compilers that emit native Microsoft Windows applications. (See the Resources section of this article for additional information.)
- J-code
- J-code is the output emitted by most Java compilers into the class files. J-code can be thought of as object code for the
Java virtual machine.
- Portability
- Portability refers to the ability to run a program on different machines. Running a given program on different machines can
require different amounts of work (for example, no work whatsoever, recompiling, or making small changes to the source code).
When people refer to Java applications and applets as portable, they usually mean the applications and applets run on different
types of machines with no changes (such as recompilation or tweaks to the source code).
Now that we have covered some essential terms, we'll explain each of the three types of Java portability.
Java as a language: source code portability
As a programming language Java provides the simplest and most familiar form of portability -- source code portability. A given
Java program should produce identical results regardless of the underlying CPU, operating system, or Java compiler. This idea is not new; languages
such as C and C++ have provided the opportunity for this level of portability for many years. However, C and C++ also provide
numerous opportunities to create non-portable code as well. Unless programs written in C and C++ are designed to be portable
from the beginning, the ability to move to different machines is more theoretical than practical. C and C++ leave undefined
details such as the size and endianism of atomic data types, the behavior of floating-point math, the value of uninitialized
variables, and the behavior when freed memory is accessed.