HPlogo Communicator 3000 MPE/iX Release 6.0 (Platform Software Release C.60.00): HP 3000 MPE/iX Computer Systems > Chapter 10 Technical Articles

Developer's Kit for Java/iX

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

by Mike Yawn
Commercial Systems Division

Background

The Java development environment (including compiler, runtime, and class libraries) was first ported to MPE in 1996, and various versions have been available as unsupported freeware since that time. Beginning with MPE/iX 6.0, a version of Java is now bundled with the MPE operating system.

Java/iX for the HP 3000 was initially developed as an unsupported "freeware" product by engineers within Hewlett-Packard. With the release of MPE/iX version 6.0, the current Java/iX version is being bundled into FOS as the first step in turning Java/iX into a fully supported HP product. While HP is committed to providing support for Java in MPE/iX, the current release contains a few limitations that you should be aware of:

  • This first release of Java/iX will be supported by the Response Center on a "best effort" basis.

  • Performance has been a secondary concern to reliability in our engineering efforts up to this point. While Java/iX includes HP's own Just-In-Time (JIT) compiler which allows Java programs to be converted into native PA-RISC code at runtime, customers may find that the overall performance for some Java applications will be less at this time than on other platforms.

  • This release of Java/iX does not pass 100% of the Java Compatibility Kit test suite, which prevents it from being officially labeled as 'Java Compatible' at this time.

  • Sun is developing a functionality specification for Java running on server systems such as the HP 3000. It is likely that we will target this specification for the functionality to be included in future releases of Java/iX. Thus it is possible that some of the Java APIs which are not normally used in server-side Java programs, but which are included in the current Java/iX release, may not be supported in future versions.

Work is actively being done to address these issues.

Installing or Updating Java

If you have not downloaded and installed any version of Java from the JAZZ web server or an Interex freeware tape, then you can safely install the version of Java included with this release of MPE/iX. If you have installed another version of Java, you should check to see whether the one included with the OS is more recent. If you have installed any version of Java on your system, you can determine the version by typing the following at the POSIX shell prompt (or at a CI prompt if you have set up the proper UDCs to allow Java to be accessed from the Command Interpreter):

java -version

You can compare this to the version number in the readme file (README.INSTALL.JAVA) after updating your MPE/iX system to 6.0. If the 6.0 version is more recent, you can install it by typing the following at the MPE CI prompt:

:STREAM JINSTJDK.INSTALL.JAVA

Shell or CI?

You can run Java from the MPE Command Interpreter or from the POSIX shell. These are the differences between the two environments:

  • The MPE Command Interpreter will launch Java programs faster, because of the efficiency of MPE's CREATEPROCESS mechanism compared to POSIX fork() and exec().

  • The POSIX shell provides intelligent default values for several environment variables, so the user does not, in most cases, have to provide values.

Java uses six environment variables, and Java will be easier for you to work with if you provide values for these via a command file or UDC (if you use Java from the MPE CI) or a shell script or .profile (if you use Java from the POSIX shell). These variables are:

  • SYSNAME

  • PATH (or HPPATH)

  • CLASSPATH

  • LD_LIBRARY_PATH

  • THREADS_FLAG

  • DISPLAY

Descriptions of these variables and their typical settings follow.

SYSNAME Variable

Example of setting SYSNAME from the shell:

shell/iX> export SYSNAME=hp3000

The SYSNAME variable is tested by some of the shell scripts provided with Java. It does not need to be set in the MPE CI environment, since the Java shell scripts are not used when running from the CI. It must be set to hp3000, exactly as shown above.

PATH (or HPPATH) Variable

Example of setting PATH from the shell:

shell/iX> export PATH=$PATH:/usr/local/java/latest/bin

Example of setting HPPATH from the CI:

:setvar HPPATH HPPATH+",/usr/local/java/latest/bin/PA-RISC/green_threads"

These variables are not Java-specific, but rather the standard path variables used to search for executable program files. The Java executable program files are in the directory shown for the HPPATH variable. When executing Java from the CI, the actual program binary files are executed. When executing Java from the shell, we do not execute the Java program files directly, but instead execute shell "wrapper" scripts that are in the directory indicated by the PATH statement above. These shell scripts set standard env variables for us (such as CLASSPATH and LD_LIBRARY_PATH, shown below), so that we don't need to specify values for these unless we wish to add to or replace the standard settings.

CLASSPATH Variable

Example of setting CLASSPATH from the shell:

shell/iX> export CLASSPATH=$CLASSPATH:(add your stuff here)

Example of setting CLASSPATH from the CI:

:setvar CLASSPATH "/usr/local/java/latest/lib/classes.zip:(add your stuff here)"

Like the PATH variable, the CLASSPATH variable is a colon-separated list of directories (or zipped archive files) to search. While the PATH and HPPATH variables list the directories to search for program files, the CLASSPATH variable lists the directories to search for Java classes.

The standard Java classes (such as those that make up the java.lang, java.io, and java.net packages) are all bundled together in a single ZIP format archive file, called classes.zip and stored at the location shown in the :SETVAR command above. When running from the shell, the wrapper script sets the CLASSPATH for you to include this file; when running from the CI, you must create a CLASSPATH variable to include the classes.zip file. In either case, any additional classes, such as application or applet-specific classes you have written or obtained from a third party, must also be listed in the CLASSPATH. Because locations on the CLASSPATH are searched in the order you specify, best performance is obtained when you order the directories on the CLASSPATH so that the directories containing the most frequently-accessed classes are listed first. (In most cases, this means that the standard classes.zip file should come before any others).

LD_LIBRARY_PATH Variable.

Example of setting LD_LIBRARY_PATH from the shell:

shell/iX> export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:(add your stuff here)

Example of setting LD_LIBRARY_PATH from the CI:

:setvar LD_LIBRARY_PATH "/usr/local/java/latest/lib/PA-RISC/green_threads:
(add your stuff here)"

Again, we specify a colon-separated list of directories to search. In this case, we're providing the locations to search for library (XL) files that contain native (that is, platform-specific) code. The java classes—all the files that go into classes.zip—are the same on all platforms. The platform-specific code is written in C, and compiled into shared libraries (XLs on MPE). The standard Java runtime libraries are in the location shown on the MPE :SETVAR command above; the Java shell wrappers will include this location automatically when running Java from the shell. Users usually do not need to add additional locations to this variable; it is used only if you have written (or obtained from a third party) Java code that includes native (non-portable) code. One example of such a library is the TurboIMAGE/XL class library for MPE, which includes an XL that has the interfaces to the IMAGE/SQL intrinsics.

THREADS_FLAG Variable

Example of setting from the shell:

shell/iX> export THREADS_FLAG=green

The THREADS_FLAG variable is only needed when running from the shell, and tells the java shell wrappers to use the binaries found in the green_threads subdirectory (when running from the CI, we've already indicated this in our setting of the HPPATH variable). There are two possible ways to implement multithreading when porting Java to a new platform: using kernel threads (with binaries in the native_threads directory) or using library threads (with binaries in the green_threads directory). The current MPE implementation uses green_threads, although a native_threads version may be developed in the future. If so, the THREADS_FLAG variable could be set to native to select the kernel threads implementation (and the HPPATH variable would be changed for CI users to select the native_threads directory).

DISPLAY Variable

Example of setting from the shell:

shell/iX> export DISPLAY=sysname:0

Example of setting from the CI:

:setvar DISPLAY "sysname:0"

The DISPLAY value is used by the AWT and Applet classes to locate the display device. Only X-Windows compatible display devices (UNIX workstations, X-terminals, or PCs running X-Windows emulation software) are supported for the display device. Most HP 3000 Java users probably won't need the AWT on the HP 3000; user-interface code is usually downloaded to a Web browser or run in some other client-server type of configuration. We certainly recommend this for your own development:

  • Design the user interface as a separable module that can be executed on a client, and leave application logic and database access modules on the server.

You may, however, encounter Java applications that aren't designed this way, and the MPE AWT implementation will allow you to execute these applications, if you can provide an X-Windows capable display device accessible from the HP 3000.

Java Directory Structure

Java is installed in MPE's hierarchical file system under the path /usr/local/java. There are several additional directory levels beyond this point.

The next level down specifies the Java version. For example, Version 1.1.5 of Java is installed under /usr/local/java/jdk1.1.5. There is also a symbolic link called latest that you can use to access the most recent version of Java, so that you do not need to change shell scripts, jobstreams, and command files every time you install a new version of Java. Thus, you can use /usr/local/java/latest/ as the path to any Java components to use the latest installed version. When you install new versions, you can remove this link and create a new one. If you have software that must be run with a particular version of Java, you can always specify a specific version directory rather than latest.

Two major hierarchies, lib and bin, are under /usr/local/java/latest, as well as the optional hierarchies, demo and doc, and a number of files such as the latest README file.

The bin hierarchy contains Java program files and shell scripts used to run those programs. Under /usr/local/java/latest/bin are shell scripts used to run each of the Java components (described in the next section). So, for example, /usr/local/java/latest/bin/java is the script to run the latest version of the Java interpreter. If the PATH (or HPPATH) variable is set correctly, it is not necessary to specify this entire path; java MyClass would be sufficient.

The actual program binaries are two levels further down in the hierarchy. Under /usr/local/java/latest/bin is the directory PA-RISC. In the future, an additional subdirectory may be created at this level to contain IA-64 binaries. Under the PA-RISC directory is the directory green_threads. This directory holds the actual Java programs. Green threads is a simulated threads library provided by JavaSoft. If at some point we choose to create a version of Java that uses MPE's kernel threads, a native_threads subdirectory will be created at this level to hold that version of the binaries. The lib hierarchy follows the same structure as the bin hierarchy, with PA-RISC and green_threads subdirectories. One file residing at the top level of the lib hierarchy, classes.zip, is an archive file that contains all of the standard Java classes. You do not have to unzip it to access this archive (in fact, you can access it faster as a single zip file than as hundreds of individual disk files). At the bottom level of the hierarchy are a number of specialized libraries that are dynamically loaded when needed for certain Java tasks. For example, libnet.sl contains the Java networking code, and libawt.sl contains code used by the Abstract Windowing Toolkit.

The demo directory holds a number of demo programs.

The doc directory holds HTML format API documentation.

Using Java

Writing Java Programs

There are no unique tools on the HP 3000 for writing Java programs; you just select your favorite word processor and enter the program text. You can use either a traditional HP 3000 editor such as EDIT/3000 or HP EDIT, or you can use the vi editor from within the POSIX shell. The naming of a Java source file should follow the following conventions:

  • The name must be followed by the extension .java

  • The name is case-sensitive. While not a requirement, it is conventional to use mixed case in class names, with an initial capital and additional capitals used if the class name contains more than one word (for example, HelloWorld.java).

  • Java files must be in bytestream format. VI will create bytestream files for you. If you use another editor such as HPEDIT, you will need to use the shell's tobyte command to convert the source file to bytestream format.

Because of these requirements, if you use an editor that does not support full POSIX naming conventions, you must either use file equations or rename your source file to meet the requirements.

If your program is part of a package, it needs to be placed in an HFS directory whose name is the same as the package name.

For an example, consider the following, perhaps the simplest possible Java program:

public class HelloWorld
{
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

Because the class name is HelloWorld, this program needs to be saved as HelloWorld.java.

Compiling a Program

The compiler for Java programs is called javac, so the above program is compiled simply by:

javac HelloWorld.java

This command can be entered at either a CI prompt or at a shell prompt. The compiler will produce a class file called HelloWorld.class.

Executing a Program

To run the above program, type at either the CI or shell prompt:

java HelloWorld

Note that the .class extension isn't needed (and will cause an error if specified).

Where to Go for More Information

For an introductory book on Java, Java in a Nutshell(O'Reilly, 1997), now available in a second edition covering JDK 1.1, is an excellent work. Many Java users have recommended Teach Yourself Java in 21 Days(O'Reilly, 1997) as another good starting point. Also highly recommended is Thinking in Java (Prentice-Hall, 1998) but also downloadable over the Web from http://www.EckelsObjects.com/javabook.html.

For more advanced topics, you'll have no problems finding books focused on the AWT, JavaBeans, JDBC, or just about any other Java topic. The books published by O'Reilly and Associates, the JavaSoft Press series published by Prentice Hall, and the official specification books (The Java Language Specification, the Java Virtual Machine Specification, and the Java API Specification (two volumes)), published by Addison-Wesley all are frequently recommended on the Internet by Java users. Your best bet is to ask others, in a forum such as USENET or SIG JAVA, for recommendations, or just be prepared to spend some time browsing at the bookstore before making your selection.

If you want to find resources on the World Wide Web, a search for "Java" in your Web browser will find more hits than you can possibly read in your lifetime. The following two URLs are good starting points:

  • The Official JavaSoft home page http://java.sun.com is updated very frequently. Check here for new releases of add-on products, such as the Beans Development Kit (BDK), Java Workshop, or Java Web Server. On-line tutorials and reference documents are available, plus access to developer resources and a wealth of other information.

  • The Home Page for Java on the HP 3000 http://jazz.external.hp.com/src/java contains the latest MPE-specific Java information and downloadable software.

SIG JAVA is the Interex Special Interest Group for Java on all HP Platforms. SIG JAVA holds discussions via the JAVA mailing list. You can subscribe by sending an email to java-request@interex.org with the message "subscribe java yourname" in the body of the message. You can then send email to the entire mailing list by addressing a message to java@interex.org.

The comp.lang.java.* newsgroups are very active, holding discussions on all aspects of Java.

MPE-specific Java issues will also be discussed on the comp.sys.hp.mpe USENET newsgroup or its mirrored mailing list, HP3000-L.

Feedback to webmaster