Any Number of Ways to Brew Java

Now that Sun officially supports Linux with each new version of the Java 2 Software Development Kit (JDK), you might assume that no other tools are needed to code Java on your favorite OS. After all, the JDK is a free (as in beer) download (available from http://java.sun.com/j2se/1.4.1) that fully supports the Java language and the ever-expanding Java 2 class library, and the command-line interpreter, compiler, and debugger are capable tools used by thousands of programmers. In fact, many of the latest Linux implementations bundle the Sun JDK.

Now that Sun officially supports Linux with each new version of the Java 2 Software Development Kit (JDK), you might assume that no other tools are needed to code Java on your favorite OS. After all, the JDK is a free (as in beer) download (available from http://java.sun.com/j2se/1.4.1) that fully supports the Java language and the ever-expanding Java 2 class library, and the command-line interpreter, compiler, and debugger are capable tools used by thousands of programmers. In fact, many of the latest Linux implementations bundle the Sun JDK.

However, the world of Java on Linux doesn’t orbit entirely around Sun. There are excellent compilers, development environments, and other implementations available — many under an open source license.

This month’s Java Matters is devoted to several of these Java alternatives, with an emphasis on those that have practical use for Java programmers (as opposed to some of the interesting research projects in virtual machine design and non-Java bytecode compilation). Two of the alternatives, Blackdown Java and the IBM JDK, are very similar to the official Sun JDK.

For comparative purposes, it’s worth noting that the official JDK for Linux requires kernel version 2.2.12 and GNU libc (glibc) version 2.1.2-11 or later.

IBM’s jikes for Linux

jikes is a command-line compiler from IBM that offers extremely fast compilation, makefile generation, and incremental builds. The program, released under the open source IBM Public License, is available from http://www-124.ibm.com/developerworks/oss/jikes. If you’re running Debian, SuSE, Mandrake, or Yellow Dog (among others), it may already be on your system. jikes requires Sun’s Java runtime environment to access the files in the Java 2 class library.

Using jikes as a drop-in replacement for Sun’s javac compiler is easy because it uses many of the same arguments and is current through Java 2 version 1.4, supporting the new assert keyword. jikes also offers many unique features that go beyond the standard compiler:

  • The argument +F causes jikes to do a complete dependency check, recursively checking each required class to make sure that all classes are up-to-date.

  • +M creates text files with dependency information for each class that’s compiled. The files, named Classname.u, contain a simple list of dependencies, as in this example:

$ jikes +M DmozServer.java
$ cat DmozServer.u
DmozServer.class : DmozServer.java
DmozServer.class : DmozHandler.java
DmozServer.class : DmozHandler.class

The +M dependency check skips any classes that are contained within archives in the CLASSPATH, assuming that the files won’t change as this specific project is being worked on.

There’s one thing to watch for as jikes is installed: Unlike javac, jikes requires a CLASSPATH environment variable with a reference to the Java 2 class library. If JAVA_HOME refers to the directory where the Java 2 SDK was installed, the following commands add the library to the CLASSPATH:


The features listed above are nice, but the primary reason that jikes is so popular is its speed of compilation. jikes is also good to have around when another compiler’s error messages are confusing. jikes has unusually informative messages. For example, compare the messages displayed by javac and jikes when a class refers to a Helper instance variable as val when its real name is value. First, javac:

User.java:4: cannot resolve symbol
symbol : variable val
location: class Helper
System.out.println(“Value: ” + .val);
1 error

Next, jikes:

*** Semantic Error: No field named “val” was found in type “Helper”. However,
there is an accessible field “value”
whose name closely matches the name “val”.

As you can see, the jikes message is a little more helpful.

Blackdown Java

For years, the members of the Blackdown Project (http://www.blackdown.org/java-linux) worked without official permission to make the Java SDK and Java runtime environment available on Linux, receiving little help and even less credit from Sun. Today, Sun bases its Linux versions of the JDK and JRE on Blackdown, and thanks project founder Karl Asha and other contributors on its web site.

Although Sun’s Java 2 SDK is based on Blackdown, there’s still a distinct Blackdown Java build that offers new features and bug fixes that haven’t been incorporated yet into a Sun release.

The current release of Blackdown Java is version 1.4.1-01, which is ahead of Sun’s JDK in a small number of performance enhancements and new features. The current release claims graphical and imaging performance as much as 80 percent faster in some areas, complete Large File Support (LFS), and an improved implementation of MappedByteBuffer, one of the new buffer classes in the java.nio package. The Blackdown build of the Java 2 SDK contains all of the familiar command-line tools and class libraries. The Blackdown programmers are also working on a Linux port of the Java 3D library, which is available as a beta release.

Blackdown requires Linux kernel version 2.4.18 and glibc v2.2.5 or later. Contrary to popular belief, Blackdown isn’t an open source project; Blackdown’s work is produced under license from Sun.

In general, the Sun and Blackdown releases are extremely similar. For this reason, the deciding factor in choosing between them may be the relative lack of community support for the Blackdown version — since many more programmers are using Sun’s official SDK, more help is available for that build on USENET, mailing lists, and other Internet discussion forums.

GCJ, the GNU Compiler for Java

GCJ is an intriguing open source Java development tool developed by Pers Bothner and part of the GNU Compiler Collection (GCC). GCJ is released under the GNU Public License with one notable exception, which will be described shortly. The GCJ software is available from GNU’s GCJ web site at http://gcc.gnu.org/java.

Although it’s officially described as a compiler, GCJ is actually intended to be a replacement for the entire Java SDK. It can be used to write, compile, and run Java class files in bytecode format. It also supports compilation of Java source code or bytecode into executable native code.

The GCJ compiler takes an approach that’s unorthodox for Java, but very familiar to GCC users. Bothner, who began the project at Cygnus Solutions in 1996, describes it as “radically traditional.” Through a process he calls “ahead of time compilation,” GCJ converts a Java program into a form compatible with other GCC languages, which enables the compiler to employ standard GCC optimizations. The end result is native code that’s competitive in execution speed to just-in-time compilers, is faster to start, and takes up considerably less memory.

Compiled code is linked with libgcj, a runtime library that contains a bytecode interpreter, garbage collector, and an open-source implementation of many classes in the Java 2 class library (with some important exceptions).

The GPL licensing exception involves libcgj: Linking code with the library does not by itself make the program fall under the GPL.

Java 2 class library support is likely to be the biggest issue for people considering GCJ. Many of the non-graphical packages are comprehensively implemented, including java.beans, java.io, java.lang, java.lang.ref, java.math, java.net, java.rmi, java.sql, java.util, and java. util.jar. The windowing classes are not as complete — some java.awt and javax.swing classes have been ported, but not enough for use in real graphical applications. Others are in various stages of implementation, except javax.crypto; GCJ developers recommend using GNU Crypto instead.

Using GCJ to compile programs is similar to gcc. Here, an Example.java source code file is compiled into an executable named ExampleExe and run:

$ gcj –main=Example -o ExampleExe Example.java
$ ./ExampleExe

This syntax ought to be familiar, aside from the –main argument, which specifies the class that contains the application’s main() method.

The compiler is only one part of GCJ, which also includes a Java interpreter called gij and support for the Compiled Native Interface, a way to write C++ methods within a Java class that use C++ syntax for method calls and variable access. The March 2002 edition of “Java Matters” includes more information on GCJ and can be read online at http://www.linux-mag.com/2002-03/java_01.html.

The IBM Developer Kit for Linux

Known unofficially as the “IBM JDK,” the IBM Developer Kit for Linux is a development and runtime environment that includes IBM’s just-in-time Java compiler, a mixed-mode interpreter and a re-engineered Java 2 virtual machine. The software, which is bundled with some commercial products such as IBM WebSphere, is available as a free download from http://www-106.ibm.com/developerworks/java/jdk/linux140.

The IBM JDK feels like a build of the Java 2 SDK, offering command-line tools that have the same names and features as the official Java 2 SDK. There are some important differences, however. For example, Red Hat Linux systems running a kernel prior to 4.10 must disable floating stacks support or the IBM JDK Java interpreter won’t function correctly. To disable floating stacks, set the environmental variable LD_ASSUME_KERNEL to 2.2.5 as follows:

$ export LD_ASSUME_KERNEL=2.2.5

IBM’s JDK adds a few enhancements. The IBM JDK includes Version 2.3 of the LotusXSL-Java XSLT processor, and a new com.ibm.math package includes alternate versions of the BigDecimal and MathContext classes found in java. math.

One of the downsides to using IBM’s Java SDK is the lack of documentation: There’s only one 73 KB web page that represents the entire user guide, and the support materials on the IBM DeveloperWorks web site are incomplete. Worse, nothing describes the required versions of the Linux kernel or glibc necessary to use the kit.

Any Flavor, as Long as it’s Java

All of the Java tools mentioned here were evaluated by compiling several large Java programs and seeing how well they fared with sample code that intentionally creates thousands of object and a few other tasks. On an Intel 586 system running Red Hat Linux 7.1, the performance of all of the software development kits was surprisingly similar. Speed differences would undoubtedly be found using more formal benchmarking tools such as VolanoMark. (A comprehensive VolanoMark benchmark was last conducted in December 2001; see http://www.volano.com/benchmarks.html.)

However, in ordinary day-to-day use, the strongest distinction between these tools is their number of features, rather than compilation or execution speed.

Rogers Cadenhead is a Web application developer and the coauthor of “Teach Yourself Java 2 in 21 Days, Third Edition” from Sams Publishing. To contact Cadenhead, visit his weblog at http://www.cadenhead.org/workbench.

Comments are closed.