Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

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

  • Print
  • Feedback
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.

  • Print
  • Feedback

Resources
  • Harbison and Steele, 1991, CA Reference Manual. Englewood Cliffs, NJ:Prentice Hall.
    This book provides many good examples of differing behavior by different implementations of the C programming language.
  • Alvin Toffler, 1990, PowerShift. New York:Bantam Books.
    PowerShift provides a good discussion of how power, wealth, and knowledge interact. Toffler doesn't provide a lot of predictions in this book, but mostly focuses on trends already underway.
  • Some programming language implementations that either support the JVM or run under it:
  • Ada95
    http://www.adahome.com/Resources/Ada_Java.html
    This is a page of links to Ada implementations that emit J-code, a comparison of the Java language with the Ada95 language and other Ada links.
  • BASIC
    http://www.mcmanis.com/~cmcmanis/java/javaworld/examples/BASIC.html
    From the author:
    This is a simple BASIC interpreter I wrote in Java. When you load this page a new window will pop up with the interpreter running in it (well loading first). It's a primitive BASIC, uses line numbers, implements most of BASIC-80.
  • E
    http://www.communities.com/products/tools/e/index.html
    This is the home page for a language that builds on Java. The site contains a whitepaper on the language, tutorial, programmer's manual and other neat things.
  • Forth
    http://www.mistybeach.com
    This site contains Misty Beach Forth. Misty Beach Forth is an implementation of the Forth language that runs in a Java environment. It does not (yet) produce independent class files.
  • Java
    http://www.javasoft.com
    This is the JavaSoft home page.
  • Prolog
    http://munkora.cs.mu.oz.au/%7Ewinikoff/wp/
    This is the home page for W-Prolog, an implementation of Prolog written in Java.
  • Rexx
    http://www2.hursley.ibm.com/netrexx/doc-netrexx-2.htm
    This is the home page for NetRexx, a dialect of the Rexx language.
  • Scheme
    http://www.copsol.com/kawa/index.html
    This is the home page for Kawa Scheme. Quoting from the home page:
    Kawa is an implementation of the Scheme programming language. It is implemented in Java, and compiles Scheme into Java byte-codes.