Using Sun Technology at Sheffield Sun@Sheffield

Java

The Language

Java is an object-oriented programming language; all programs are written in terms of a system of objects which each have their own internal state and interact with each other by calling methods exposed by the object. Syntactically, Java is block-structured and has similarities with C and C++. However, unlike these languages, Java enforces the object-oriented style of programming (even a simple application to print 'Hello World' on the screen must consist of an object with a single method) and removes many of the more ambiguous and dangerous features, such as the direct manipulation of memory references. Java is also strongly typed; if you declare a variable to contain a number, you can't then use that variable to refer to a string of characters.

Java allows classes of objects to inherit variables and behaviour from one other class (its superclass) and to implement multiple interfaces (a series of method signatures which must be provided by the class). When a problem occurs, Java has support for throwing exceptions, which can be handled appropriately by the calling code or simply returned to the user.

The Virtual Machine

Usually, Java code is compiled not to the native code of any particular machine, but to a special bytecode language which is then executed by a Java Virtual Machine. This allows Java code to be compiled and run on any Java virtual machine, simplifying the process of porting the code to a different architecture to largely being a case of making sure that a Java virtual machine is available for that architecture.

The Java runtime environment consists of such a virtual machine and the Java class library. The huge size of Java's class library means that there is often an existing set of classes within that library that can be used to obtain the required functionality for a program. So there is less need to implement many things that it would be necessary to implement in C or C++, as the application developer can rely on this library being installed.

Obtaining and Installing Java

There are a number of ways of obtaining Java support for your system. Here, for simplicity, we will concentrate on support for desktop x86 and x86_64 machines, as this is the most commonly used platform.

Sun's implementation of the Java Development Kit (JDK) was released under the GPL in 2006/7 as OpenJDK. This represents the codebase that will eventually become JDK 1.7 or 7 (depending on whether you following the internal or marketing versioning system). Released versions of Sun's JDK are still proprietary, but a backport of OpenJDK to version 6 is underway.

Even OpenJDK itself is still not fully Free Software, as it still relies on a number of proprietary encumberances from third party source code which Sun is as yet unable to release. To obtain and use OpenJDK today, you need to look at IcedTea which is already being shipped with Fedora Core 8 and recent versions of Ubuntu.

The existing Free Java solutions which existed before the OpenJDK release still exist and have an active developer community. The focus there is on the class library, implemented by the GNU Classpath project, which many virtual machines make use of. As such, you have a choice of which virtual machine to use with GNU Classpath — these include Kaffe, JamVM, JikesRVM and CACAO),. If you want a more complete solution, take a look at GCJ, which is part of the GNU Compiler Collection (GCC). This also has the ability to compile Java to native code rather than the intermediate bytecode representation. This does however tend to lag behind the main GNU Classpath codebase, due to the slower release period of GCC.