AS400 Developer Kit For Java (Rzaha)
AS400 Developer Kit For Java (Rzaha)
Contents v
vi AS/400 Developer Kit for Java
Chapter 1. AS/400 Developer Kit for Java
What it is:
The AS/400 Developer Kit for Java is optimized for use in an AS/400 server
environment. It utilizes the compatibility of Java programming and user interfaces,
so you can develop your own applications for the AS/400 system.
The AS/400 Developer Kit for Java allows you to create and run Java programs on
AS/400. The AS/400 Developer Kit for Java is a compatible implementation of the
Sun Microsystems, Inc. Java Technology, so we assume that you are familiar with
their Java Development Kit (JDK) documentation. To make it easier for you to
work with their information and ours, we provide links to Sun Microsystems,
Inc.’s information.
If for any reason our links to Sun Microsystems, Inc. Java Development Kit
documentation do not work, refer to their HTML reference documentation for the
information that you need. You can find this information on the World Wide Web
Select any of these topics for more details on how to use the AS/400 Developer Kit
for Java:
v Print this topic provides details on how to download a printable PDF file or a
zipped package of AS/400 Developer Kit for Java HTML files.
v What’s new in V4R5 highlights the latest product and information updates.
v Getting started gives information about installation, configuration, how to create
and run simple Hello World Java programs, downloading and installing, and
release to release compatibility.
v Concepts introduces the specific concepts that you should be familiar with when
using the AS/400 Developer Kit for Java. Also provides very basic Java
definitions for those who are looking for general details.
v Commands and tools provides details on how to use the Java commands and
Java tools.
v Other programming languages shows you how to call code that was written in
languages other than Java by using Java Native Interface (JNI),
java.lang.Runtime.exec(), interprocess communication, and the Java Invocation
API.
v JDBC driver explains how the AS/400 Developer Kit for Java JDBC driver
allows Java programs to access AS/400 database files.
v SQLJ support explains how the AS/400 Developer Kit for Java allows you to use
SQL statements that are embedded in your Java application.
To view or download the PDF version, select AS/400 Developer Kit for Java (about
943 KB or 176 pages).
To download a zipped package of the AS/400 Developer Kit for Java HTML files
to your workstation:
1. Ensure your hard drive has at least 5.0 MB of storage space:
2. Create a new directory on your hard drive.
3. Download the package. The package size is about 412 KB.
a. Select the Save to disk option.
b. Select a temporary directory as the destination for the download.
c. Click OK.
4. Unzip the package into the directory you created in step 2.
5. Open devkit.htm with your browser to view the reference.
The small links at the top of each page show you where you are in our
information. These links are displayed in a directory structure format. To see where
you are, read through the links. For example, if you look at the top of this page,
you see:
These links tell you that you are in the “What’s new” information under the
“AS/400 Developer Kit for Java” topic.
Getting started:
v See multiple JDK support for information on each JDK that IBM supports.
v See Java classpath for details on how to properly set your classpath for JDK 1.1.x
or J2SDK.
Tools and commands:
v The Java ajar tool was added to the list of Java tools that are supported by the
AS/400 Developer Kit for Java.
v See the Java appletviewer tool for new details about how to run the
appletviewer tool with Remote Abstract Window Toolkit.
v The new Dump Java Virtual Machine (DMPJVM) command was added to dump
information about the Java virtual machine for a job that you specify.
v The TGTRLS parameter was added to the Create Java Program (CRTJVAPGM)
command.
v The SUBTREE parameter was added to the Change Java Program
(CHGJVAPGM) command.
Note: In this section, we only discuss changes that are unique or interesting in the
J2SDK, version 1.2. The general information on updates from the What’s new for
Java Development Kit (JDK) 1.1.8 topic also apply to J2SDK, version 1.2.
Getting started:
v See multiple JDK support for information on each JDK that IBM supports.
v See Java classpath for details on how to properly set your classpath for JDK 1.1.x
or J2SDK.
v The selecting which mode to use when running a Java program topic was added
to explain the difference between running a Java program with interpreted,
direct execution, or Just-In-Time compile.
v For information about the Java extensions framework, see downloading and
installing Java packages on AS/400 and installing extensions for the AS/400
Developer Kit for Java.
Concepts:
v See Class Broker for Java for overview information on how to run Java
applications on a host that does not have a graphical user interface (GUI).
v Support for a Just-In-Time compiler that improves performance by compiling
code as you need it was added.
Once you have installed the AS/400 Developer Kit for Java on your AS/400, you
may choose to configure your system.
See running your first Hello World Java program for information on getting started
with the AS/400 Developer Kit for Java.
Find the JDK that you are using or want to use, and select the coordinating option
to install. You can install more than one JDK at one time. The java.version system
property determines which JDK to run. However, when you change the
java.version system property it has no effect once a Java virtual machine is up and
running.
4 1.1.8 1.1.8
/QIBM/ProdData/Java400/jdk118/
* Version 1.2 is the same as Java 2 SDK (J2SDK), Standard Edition, version 1.2.
For example, these are the results of which options you install and the command
you enter.
If your Java programs are sensitive to time of day, then time zone configuration
may be required.
If the Coordinated Universal Time Offset (QUTCOFFSET) system value is set to its
default (+00:00), then Java uses the AS/400 time as the current time. The default
value of the user.timezone Java system property setting is UTC.
A QUTCOFFSET system value and an updated locale are required for any of these:
v If QUTCOFFSET is not set to its default value, thus sensitive to time zone.
v If your Java code expects the user.timezone system property to default to a value
other than UTC.
v If you specify the user.timezone Java system property when running the java
command.
The LC_TOD category of the locale contains the tname field, which must be set to
the same value that matches your time zone. For details on how to create a locale
and format the tname field, see the AS/400 International Application Development,
SC41-5603 book.
Java system properties determine the environment in which the Java programs run.
They are similar to system values or environment variables in OS/400. A number
of properties are set when the Java virtual machine starts. You can choose to use
the system property default values or you can specify your own set of default
property values by doing either of these steps:
1. Provide a file in /QIBM/UserData/Java400, named SystemDefault.properties.
The property values that you specify in this file override the system defaults
that IBM provides. This file sets the default system properties for all Java
virtual machines that run on your AS/400 system.
2. Or, place a SystemDefault.properties file in your own user.home path. This file
and the properties that it contains override those in
Chapter 2. Getting started with the AS/400 Developer Kit for Java 9
/QIBM/UserData/Java400/SystemDefault.properties. This file sets the default
system properties for all Java virtual machines that run for you.
See running your first Hello World Java program for information on getting started
with the AS/400 Developer Kit for Java.
To create, compile, and run your own Hello World Java program:
1. Create the source file as an American National Standard Code for Information
Interchange (ASCII) text file in the integrated file system.
a. Name your text file Hello.java. For more information about how you can
create and edit your file, see creating and editing Java source files.
b. Make sure that your file contains this source code:
class Hello {
public static void main (String args[]) {
System.out.println(“Hello World”);
}
}
2. Compile the source file.
Creating and running Java programs with the AS/400 Developer Kit for
Java
You can create Java application and applet programs by using the AS/400
Developer Kit for Java. You can also use Sun Microsystems, Inc. Java Development
Kit (JDK) that is available on a workstation.
Chapter 2. Getting started with the AS/400 Developer Kit for Java 11
Java classpath
The Java virtual machine uses the Java classpath to find classes during runtime.
Java commands and tools also use the classpath to locate classes. The default
system classpath, the CLASSPATH environment variable, and the classpath
command parameter all determine what directories are searched when looking for
a particular class.
The default system classpath is system-defined and you cannot change it. On
AS/400, the default classpath specifies where to find the classes that are part of the
AS/400 Developer Kit, the Remote Abstract Window Toolkit (AWT), and other
system classes.
To find any other classes on the system, you must specify the classpath to search
by using the CLASSPATH environment variable or the classpath parameter. The
classpath parameter that is used on a tool or command overrides the value that is
specified in the CLASSPATH environment variable.
You can work with the CLASSPATH environment variable using the Work with
Environment Variable (WRKENVVAR) command. From the WRKENVVAR display,
you can add or change the CLASSPATH environment variable. The Add
Environment Variable (ADDENVVAR) command and Change Environment
Variable (CHGENVVAR) command either add or change the CLASSPATH
environment variable.
You can set the CLASSPATH variable in the Qshell environment by using the
export utility that is available using the Qshell Interpreter.
These commands add the CLASSPATH variable to your environment and set it to
the value “ .:/myclasses.zip:/Product/classes.”
v This command sets the CLASSPATH variable in the Qshell environment:
export -s CLASSPATH=.:/myclasses.zip:/Product/classes
v This command sets the CLASSPATH variable from the command line:
ADDENVVAR ENVVAR(CLASSPATH) VALUE(“.:/myclasses.zip:/Product/classes”)
J2SDK searches for classes differently than JDK 1.1.x. JDK 1.1.x searches the system
classpath first, then any user-specified classpaths. J2SDK searches the bootstrap
classpath first, then the extension directories, then the classpath.
So, the search order for JDK 1.1.x, using the example code above, is:
1. The default system classpath,
2. The current working directory,
6. The classes directory in the Product directory in the “root” (/) file system.
When entering the Qshell environment, the CLASSPATH variable is set to the
environment variable. The classpath parameter specifies a list of path names. It has
the same syntax as the CLASSPATH environment variable. A classpath parameter
is available on these tools and commands:
v java command in Qshell
v javac tool
v javah tool
v javap tool
v javadoc tool
v rmic tool
v Run Java (RUNJVA) command
For more information about the above commands, see commands and tools. If you
use the classpath parameter with any of these command or tools, it ignores the
CLASSPATH environment variable.
Note: Use caution when specifying NONE or POST because unpredictable results
occur if a system class cannot be found or is incorrectly replaced by a user-defined
class. Therefore, you should allow the system default classpath to be searched
before any user-specified classpath.
See Java system properties for information about how to determine the
environment in which Java programs run.
Chapter 2. Getting started with the AS/400 Developer Kit for Java 13
For more information, see the OS/400 Program and CL Command APIs, SC41-5870
SystemDefault.properties file
The SystemDefault.properties file is a standard Java properties file. You can
specify default properties in a SystemDefault.properties file. The
SystemDefault.properties file that is in your home directory takes priority over the
SystemDefault.properties file that is in the /QIBM/UserData/Java400 directory.
You can specify the values of properties in the SystemDefault.properties file just
like you do in any Java properties file.
The extension mechanism allows the Java virtual machine to use the extension
classes in the same way that the virtual machine uses the system classes. The
extension mechanism also provides a way for you to retreive extensions from
specified uniform resource locators (URLs) when they are not already installed in
the Java Development Kit (JDK) or Java 2 Runtime Environment, Standard Edition,
version 1.2.
Where extensionToInstall.jar is the name of the zip or JAR file that contains the
extension that you wish to install.
When you create a link to an extension by using the Add Link Object
(ADDLNKOBJ) command, the list of files that the extension class loader searches
changes for every Java virtual machine that is running on AS/400. If you do not want
Interpreted:
If you choose to run your Java program in the interpreted mode, the code is
verified and a Java program object is created to hold the pre-verified form of the
program. Each bytecode is interpreted at runtime.
For information on running your Java program in the interpreted mode, see the
Run Java (RUNJVA) command.
Direct Execution:
If you choose to run your Java program using direct execution, the code is verified
and a Java program object is created to hold the pre-verified form of the program.
Machine instructions for a method are generated during the first call to that
method, and saved for use the next time that the program runs. One copy is also
shared for the entire system.
For information on running your Java program using direct execution, see the Run
Java (RUNJVA) command.
If you choose to run your Java program using the Just-In-Time compiler, the code
is verified and an associated Java program is created to hold the pre-verified form
Chapter 2. Getting started with the AS/400 Developer Kit for Java 15
of the program. Machine instructions for a method are generated during the first
call to that method, and saved for the duration of the Java virtual machine run.
To use the JIT compiler, you need to set the compiler value to jitc. You can set the
value by adding an environment variable or setting the java.compiler system
property. Select one method from the list below to set the compiler value:
v Add the environment variable by entering the Add Environment Variable
(ADDENVVAR) command on the AS/400 command line. Then, run your Java
program using the Run Java (RUNJVA) command or JAVA command. For
example, enter
ADDENVVAR ENVVAR (JAVA_COMPILER) VALUE(jitc)
JAVA CLASS(Test)
v Set the java.compiler system property on the AS/400 command line. For
example, enter JAVA CLASS(Test) PROP((java.compiler jitc))
v Set the java.compiler system property on the Qshell Interpreter command line.
For example, enter java -Djava.compiler=jitc Test
Once you set this value, the JIT compiler optimizes all of the Java code before
running it.
The most common way to use the Just-In-Time (JIT) compiler, is with the jit_de
option. When running with this option, programs that have already been
optimized with direct execution, run in direct execution mode. Programs that have
not been optimized for direct optimization, run in JIT mode.
To use JIT and direct execution together, you need to set the compiler value to
jitc-de. You can set the value by adding an environment variable or setting the
java.compiler system property. Select one method from the list below to set the
compiler value:
v Add the environment variable by entering the Add Environment Variable
(ADDENVVAR) command on the AS/400 command line. Then, run your Java
program using the Run Java (RUNJVA) command or JAVA command. For
example, enter
ADDENVVAR ENVVAR (JAVA_COMPILER) VALUE(jitc_de)
JAVA CLASS(Test)
v Set the java.compiler system property on the AS/400 command line. For
example, enter JAVA CLASS(Test) PROP((java.compiler jitc_de))
v Set the java.compiler system property on the Qshell Interpreter command line.
For example, enter java -Djava.compiler=jitc_de Test
Once this value is set, the Java program for the class file that was created as direct
execution is used. If the Java program was not created as direct execution, the class
file is optimized by the JIT prior to running. For more information, see the
comparison of Just-In-Time compiler and direct execution.
You can create and edit a Java source file with Client Access and a
workstation-based editor.
On a workstation:
You can create a Java source file on a workstation. Then, transfer the file to the
integrated file system by using file transfer protocol (FTP).
You can create a Java source file as a text file by using source entry utility (SEU).
For information on storing files, see files in the integrated file system.
Java programs used with graphical user interface (GUI) require the use of a
presentation device with graphical display capabilities. For example, you can use a
personal computer, technical workstation, or network computer. AS/400 provides a
Remote Abstract Window Toolkit (AWT) capability. This capability runs
applications on AS/400 by using a full range of graphical capabilities on the
appropriate Transmission Control Protocol/Internet Protocol (TCP/IP) attached
display device. For more specific installation, setup, and overall use information,
see setting up the Remote Abstract Window Toolkit.
Chapter 2. Getting started with the AS/400 Developer Kit for Java 17
Case sensitivity and integrated file system:
Integrated file system provides file systems, which are both case-sensitive and
those that are not with regard to file names. QOpenSys is an example of a
case-sensitive file system within the integrated file system. Root, ’/’, is an example
of a case-insensitive file system. For more information about the integrated file
system, see the “File Systems” information in the OS/400 Integrated File System
Introduction.
ZIP files and JAR files contain a set of Java classes. When you use the Create Java
Program (CRTJVAPGM) command on one of these files, the classes are verified,
converted to an internal machine form, and if specified, transformed to AS/400
machine code. You can treat ZIP files and JAR files like any other individual class
file. When an internal machine form is associated with one of these files, it remains
associated with the file. The internal machine form is used on future runs in place
of the class file to improve performance. If you are unsure whether a current Java
program is associated your class file or JAR file, use the Display Java Program
(DSPJVAPGM) command to display information about your Java program on
AS/400.
In previous releases of the AS/400 Developer Kit for Java, you had to recreate a
Java program if you changed the JAR file or ZIP file in any way, because the
attached Java program would become unusable. This is no longer true. In many
cases, if you change a JAR file or ZIP file, the Java program is still valid and you
do not have to recreate it. If partial changes are made, such as when a single class
file is updated within a JAR file, you only need to recreate the affected class files
that are within the JAR file.
Java programs remain attached to the JAR file after most typical changes to the
JAR file. For example, these Java programs remain attached to the JAR file when:
v Changing or recreating a JAR file by using the ajar tool.
v Changing or recreating a JAR file by using the jar tool.
v Replacing a JAR file by using the 0S/400 COPY command or the Qshell cp
utility.
Note: Java programs do not remain intact with the COPY command, however,
Java programs do remain intact with the move object (MOV) command.
Anytime you copy a JAR file, you need to run the CRTJVAPGM command
against the resulting JAR file for performance and space. Or, let the Java
programs be created automatically, as needed, when the application runs.
If you access a JAR file in the integrated file system through Client Access or from
a mapped drive on a personal computer (PC), these Java programs remain
attached to the JAR file when:
v Dragging and dropping another JAR file onto the existing integrated file system
JAR file.
v Changing or recreating the integrated file system JAR file by using the jar tool.
v Replacing the integrated file system JAR file by using the PC copy command.
When a jar file is changed or replaced, the Java program that is attached to it is no
longer current.
See runtime performance for more detailed information about the performance
characteristics of JAR files.
In Java 2 SDK, Standard Edition, version 1.2, extensions are packages of Java
classes that you can use to extend the functionality of the core platform. An
extension or application is packaged in one or more JAR files. The extension
mechanism allows the Java virtual machine to use the extension classes in the
same way that the virtual machine uses the system classes. The extension
mechanism also provides a way for you to retreive extensions from specified URLs
when they are not already installed in the Java Development Kit (JDK) or Java 2
Runtime Environment, Standard Edition, version 1.2.
See Installing extensions for the AS/400 Developer Kit for Java for information on
installing extensions.
The Java programs that may be attached to the class file, ZIP file, or JAR file are
not upward compatible from releases prior to V4R4. You should run the
CRTJVAPGM command on V4R4 for the best optimization when using a class file,
ZIP file, or JAR file with an attached Java program from a release prior to V4R4.
Use the Display Java Program (DSPJVAPGM) command to determine if you have
an attached Java program. Regardless, you should still run the CRTJVAPGM
command even if there is not an attached Java program from a previous release. In
either case, implicit creation occurs if you do not explicitly run the CRTJVAPGM
command, but an an explicit creation by using the CRTJVAPGM command
produces better code and uses less disk space.
If you have Java programs that were created at optimization level 40, prior to the
installation of Java 2 Software Development Kit (J2SDK), Standard Edition, version
1.2, you should recreate them by using the CRTJVAPGM command. You need to
recreate them because of changes made in the base J2SDK classes.
Note: If you create Java programs that use unique J2SDK, version 1.2 features, they
are not portable to versions prior to J2SDK, version 1.2. If your Java programs do
not use unique features, they are portable to prior versions.
Chapter 2. Getting started with the AS/400 Developer Kit for Java 19
[ Information Center Home Page | Feedback [ Legal | AS/400 Glossary ]
]
The basic Java concepts provide Java definitions for those of you who are looking
for basic details. This is general Java information, and is not specific to the AS/400.
It is only provided here as a quick reference. Reference information is also
available for Sun Microsystems Inc. Java Development Kit (JDK).
The AS/400 Developer Kit for Java is optimized for use in an AS/400 server
environment. It utilizes the compatibility of Java programming and user interfaces,
so you can develop your own applications for AS/400.
The AS/400 Developer Kit for Java allows you to create and run Java programs on
AS/400. The AS/400 Developer Kit for Java is a compatible implementation of the
Sun Microsystems, Inc. Java Technology, so we assume that you are familiar with
their Java Development Kit (JDK) documentation, and often provide links to this
information.
Unique aspects of the AS/400 Developer Kit for Java design include:
v The integration of critical Java virtual machine components below the
Technology Independent Machine Interface (TIMI).
v A Java transformer for conversion of Java bytecodes to RISC machine
instructions.
v Advanced, scalable implementations of garbage collection, object allocation, and
synchronization.
v The Remote Abstract Window Toolkit implementation that supports the java.awt
APIs.
v The Class Broker for Java that you can use for high performance graphical user
interface (GUI) services.
v A Just-In-Time compiler that improves performance by compiling code as you
need it.
The AS/400 Developer Kit for Java is not an integrated language environment
(ILE) language. It introduces a new language environment on AS/400 that is built
on Java, American National Standard Code for Information Interchange (ASCII),
integrated file system, and other industry standards.
The AS/400 Developer Kit for Java supports the common JDK tools, such as javac,
javadoc, and jar. There are also CL commands and Operations Navigator interfaces
to the AS/400 Developer Kit for Java.
For definitions of specific AS/400 Developer Kit for Java concepts and details, click
on any of these links:
v Running Java in a batch job explains how Java programs run in a batch job by
using the Submit Job (SBMJOB) command.
Not only can you use Java technology for programming applets or writing
applications, but you can use servlets to bring Java to your servers. Servlets are
protocol and platform-independent server side components that are written in Java
to dynamically extend Java enabled servers. See the IBM WebSphere Application
Java is simpler than C++ in other ways. There are no multiple inheritance of
implementation, templates, operator overloading, or header files. These
simplifications add to the versatility of the language by making it easier for
programmers to use and by reducing the risk of programming errors.
The garbage collector runs in parallel with the user-written program. Java
incorporates multithreading into its runtime and provides the language constructs
that allow a programmer to write multithreaded code. Threads allow parallel,
Java is an ideal language for network computing. You can develop both applets
and applications that run in a distributed environment. Java programs are portable
between platforms and do not require any modification or recompilation to run on
different hardware or operating system configurations.
For more detailed information about the basic Java platform or Sun Microsystems,
Inc. Java Development Kit, see these topics for background information:
v The Java platform compares how the Java environment differs from traditional
programming languages.
v Sun Microsystems, Inc. Java Development Kit provides information and details
about the Java Development Kit.
Java transformer
The Java transformer is an IBM Operating System/400 (OS/400) component that
preprocesses class files to prepare them to run using the AS/400 Java virtual
machine. The Java transformer creates an optimized program object that is
persistent and is associated with the class file. In the default case, the program
object contains a compiled, 64-bit RISC machine instruction version of the class.
The Java interpreter does not interpret the optimized program object at runtime.
Instead, it directly runs when the class file is loaded.
You do not need to do anything to start the Java transformer. It runs automatically
the first time that the class file runs on the system, unless you explicitly request
that the class file run in interpreted mode.
You can use the Create Java Program (CRTJVAPGM) command to explicitly start
the Java transformer. The CRTJVAPGM command optimizes the class file or JAR
file while the command runs, so nothing needs to be done while the program is
running. This improves the speed of the program the first time that it runs. Using
the CRTJVAPGM command, instead of relying on default optimization, ensures the
best optimization possible and also better utilizes space for the Java programs that
are associated with the class file or JAR file.
Using the CRTJVAPGM command on a class file, JAR file, or ZIP file causes all the
classes in the file to be optimized, and the resulting Java program object will be
persistent. This results in better runtime performance. You can also change the
optimization level or select an optimization level other than the default of 10 by
using the CRTJVAPGM command or the Change Java Program (CHGJVAPGM)
command. At optimization level 40, interclass binding is performed between the
classes within a JAR file, and in some cases, the classes are inlined. Interclass
binding improves the call speed. Inlining removes the call entirely. In some cases,
you can inline methods between classes within the JAR file or ZIP file. Specifying
OPTIMIZE(*INTERPRET) on the CRTJVAPGM command causes any classes that are
specified on the command to be verified and prepared to run in interpreted mode.
The Run Java (RUNJVA) command can also specify OPTIMIZE(*INTERPRET). This
parameter specifies that any classes running under the Java virtual machine are
Many garbage collectors are “stop-the-world”. This means that at the point where
a collection cycle occurs, all threads, except the thread that does garbage collection,
stop while the garbage collector does its work. When this happens, Java programs
experience a pause, and any multiple processor capability of the platform is
wasted relative to Java, while the collector does its work. The AS/400 algorithm
never stops the program threads. It allows those threads to continue operation
while the garbage collector completes its task. This prevents the pauses, and allows
all processors to be used during garbage collection.
The Java runtime environment includes a garbage collector that frees memory that
is no longer in use. The garbage collector runs automatically, as needed.
The garbage collector can also be started explicitly under the control of the Java
program using the java.lang.Runtime.gc() method.
See AS/400 Developer Kit for Java advanced garbage collection for AS/400
Developer Kit for Java specifics.
It is also possible to start the Java runtime environment by using the java
command in Qshell from the Qshell Interpreter. In this environment, the Qshell
Interpreter is running in a BCI job that is associated with an interactive job. The
Java runtime environment starts in the job that is running the Qshell Interpreter.
When the Java runtime environment starts from an interactive job, the Java Shell
Display is shown. This display provides an input line for entering data into the
System.in stream, as well as displaying data that is written to the System.out
stream and System.err stream.
You use Remote AWT with install and administration interfaces of server
applications. These interfaces typically have a minimum of complex graphics and
highly-interactive content. Remote AWT distributes AWT processing between
AS/400 and a workstation. Responsiveness of graphic-intensive and
highly-interactive operations might not be as fast as AWT implementations on
platforms with locally-attached graphic terminals.
Since AS/400 Developer Kit for Java Remote AWT is not recommended for
complex graphics or highly-interactive operations, you can use the Class Broker for
Java instead, which was designed for these environments.
For information on how to set up Remote AWT, see Setting up the Remote
Abstract Window Toolkit for Java on a remote display.
CBJ is easy to use, flexible, and hides the complexity of socket connections. Except
for a few calls to the CBJ classes to initialize the application, a brokered
client/server application appears to be a local application. CBJ handles all
communication and resource loading between the client and server. The fact that
some of the objects of the program are running on the client and some are running
on the server is almost transparent. CBJ creates client and server proxies using the
CBJ runtime. Once the broker creates the proxy objects, the client communicates
with the remote server by calling methods on the proxy of the server. Likewise, the
server object communicates with the client by calling methods on the proxy of the
client. Thus, both the client and server sides of the application appear as if they are
calling methods of local objects.
For information about using Class Broker for Java, see setting up Class Broker for
Java .
Just-In-Time compiler
A Just-In-Time (JIT) compiler is a platform-specific compiler that generates
machine instructions for each method upon the first call to that method. To
improve performance, the JIT compiler compiles code as you need it.
To understand the difference between the JIT compiler and direct execution, see
comparison of the JIT compiler and direct execution.
ILE Java
Members that are part of the library or file Stream files in the integrated file system
structure on AS/400 store source codes. contain source code.
You may redirect these streams to other files. Default handling sends the
System.out and System.err streams to a spooled file. The batch job, which results in
an input and output exception for read requests from System.in, owns the spooled
file. You can redirect System.in, System.out, and System.err within your Java
program. You can also use the os400.stdin, os400.stdout, and os400.stderr system
properties to redirect System.in, System.out, and System.err.
Note: SBMJOB sets the Current Working Directory (CWD) to the HOME directory
that is specified in the user profile.
Running the JAVA command in the above example will spawn a second job.
Therefore, the subsystem that the batch job runs in must be capable of running
more than one job.
You can verify that your batch job is capable of running more than one job by
following these steps:
1. On the CL command line, enter DSPSBSD(MYSBSD), where MYSBSD is the
subsystem description of your batch job.
2. Choose option 6, Job queue entries.
3. Look at the Max Active field for your job queue.
If the Max Active field is less than or equal to 1, and it is not *NOMAX,
enter the following on the CL command line:
CHGJOBQE SBSD(MYSBSD) JOBQ(MYJOBQ) MAXACT(*NOMAX)
Where:
v MYSBSD is your subsystem description, and
v MYJOBQ is your job queue.
The package name relates to the directory structure in which the class resides. The
integrated file system supports Java classes in a hierarchical file structure that is
similar to what you find on most PC and UNIX systems. You must store a Java
class in a directory with a relative directory path that matches the package name
for that class. For example, consider these Java class:
package classes.geometry;
import java.awt.Dimension;
public class Shape {
Dimension metrics;
// The implementation for the Shape class would be coded here ...
}
The package statement in the code above indicates that the Shape class is part of
the “classes.geometry” package. For the Java runtime to find the Shape class, store
the Shape class in the relative directory structure “classes/geometry”.
Note: The package name corresponds to the relative directory name in which the
class is stored. The Java virtual machine class loader finds the class by appending
the relative path name to each directory that is specified in the classpath. The Java
virtual machine class loader can also find the class by searching the ZIP files or
JAR files that are specified in the classpath.
The Java compiler uses the Java classpath, package name, and directory structure
to find packages and classes when compiling Java source code.
To view the system properties that this release supports, link to the version of your
choice for detailed information:
v Java Development Kit (JDK) 1.1.8
v Java 2 Software Development Kit (J2SDK), Standard Edition, version 1.2
20
Valid values:
0—No security check
10—equivalent to RUNJVA
CHKPATH(*IGNORE)
20—equivalent to RUNJVA
CHKPATH(*WARN)
30—equivalent to RUNJVA
CHKPATH(*SECURE)
os400.class.path.tools 0
os400.create.type
direct
Valid values:
interpret—equivalent to RUNJVA
OPTIMIZE(*INTERPRET) and
INTERPRET(*OPTIMIZE), or
INTERPRET(*YES)
direct—Otherwise
os400.defineClass.optLevel 20
os400.enbpfrcol
0
Valid values:
0—equivalent to CRTJVAPGM
ENBPFRCOL(*NONE)
1—equivalent to CRTJVAPGM
ENBPFRCOL(*ENTRYEXIT)
7—equivalent to CRTJVAPGM
ENBPFRCOL(*FULL)
os400.interpret
0
Valid values:
0—equivalent to CRTJVAPGM
INTERPRET(*NO)
1—equivalent to CRTJVAPGM
INTERPRET(*YES)
10
Valid values:
0—equivalent to CRTJVAPGM
OPTIMIZE(*INTERPRET)
10—equivalent to CRTJVAPGM
OPTIMIZE(10)
20—equivalent to CRTJVAPGM
OPTIMIZE(20)
30—equivalent to CRTJVAPGM
OPTIMIZE(30)
40—equivalent to CRTJVAPGM
OPTIMIZE(40)
os400.run.mode
program_create_type
Valid values:
interpret—equivalent to RUNJVA
OPTIMIZE(*INTERPRET) and
INTERPRET(*OPTIMIZE), or
INTERPRET(*YES)
program_create_type—Otherwise
os400.stdin.allowed 0
os400.verify.checks.disable 65535 This system property value is a string
that represents the sum of one or more
numeric values. For a list of these values, see
os400.verify.checks.disable numeric values.
path.separator : (colon)
This set of system properties are set based on additional system information.
The system properties are set to these system default values in Java 2 Software
Development Kit (J2SDK), Standard Edition, version 1.2.
20
Valid values:
0—No security check
10—equivalent to RUNJVA
CHKPATH(*IGNORE)
20—equivalent to RUNJVA
CHKPATH(*WARN)
30—equivalent to RUNJVA
CHKPATH(*SECURE)
os400.class.path.tools 0
os400.create.type
direct
Valid values:
interpret—equivalent to RUNJVA
OPTIMIZE(*INTERPRET) and
INTERPRET(*OPTIMIZE), or
INTERPRET(*YES)
direct—Otherwise
os400.defineClass.optLevel 20
0
Valid values:
0—equivalent to CRTJVAPGM
ENBPFRCOL(*NONE)
1—equivalent to CRTJVAPGM
ENBPFRCOL(*ENTRYEXIT)
7—equivalent to CRTJVAPGM
ENBPFRCOL(*FULL)
os400.interpret
0
Valid values:
0—equivalent to CRTJVAPGM
INTERPRET(*NO)
1—equivalent to CRTJVAPGM
INTERPRET(*YES)
os400.optimization
10
Valid values:
0—equivalent to CRTJVAPGM
OPTIMIZE(*INTERPRET)
10—equivalent to CRTJVAPGM
OPTIMIZE(10)
20—equivalent to CRTJVAPGM
OPTIMIZE(20)
30—equivalent to CRTJVAPGM
OPTIMIZE(30)
40—equivalent to CRTJVAPGM
OPTIMIZE(40)
os400.run.mode
program_create_type
Valid values:
interpret—equivalent to RUNJVA
OPTIMIZE(*INTERPRET) and
INTERPRET(*OPTIMIZE), or
INTERPRET(*YES)
program_create_type—Otherwise
os400.stdin.allowed 0
os400.verify.checks.disable 65535 This system property value is a string
that represents the sum of one or more
numeric values. For a list of these values, see
os400.verify.checks.disable numeric values.
path.separator : (colon)
Value Description
N (default) No stdio conversion is performed during read or write.
Y All stdio converts to or from the file.encoding value to job CCSID
during read or write.
1 Only stdin data converts from job CCSID to file.encoding during read.
2 Only stdout data converts from file.encoding to job CCSID during
write.
3 Both stdin and stdout conversions are performed.
4 Only stderr data converts from file.encoding to job CCSID during
write.
5 Both stdin and stderr conversions are performed.
6 Both stdout and stderr conversions are performed.
7 All stdio conversions are performed.
Value Description
Bypass access checks for local classes:
Indicates that you want the Java virtual
1
machine to bypass access checks on private
and protected fields and methods for classes
that are loaded from the local file system. It
is helpful when transferring applications,
which contain inner classes that refer to
private and protected methods and fields of
their enclosing classes.
2 Suppress NoClassDefFoundError during
early load: Indicates that you want the Java
virtual machine to ignore
NoClassDefFoundErrors, which occur
during early verification checks for
typecasting and field or method access.
4 Allow LocalVariableTable checking to be
bypassed: Indicates that if you encounter an
error in the LocalVariableTable of a class, the
class operates as if the LocalVariableTable
does not exist. Otherwise errors in the
LocaleVariableTable result in a
ClassFormatError.
7 Value used at runtime.
You can indicate the value in decimal, hexadecimal, or octal format. It ignores
values that are less than zero. For example, to select the first two values from the
list, use this AS/400 command syntax:
JAVA CLASS(Hello) PROP((os400.verify.checks.disable 3))
Note: Files and directories that do not have execute authority (*X) always appear
to have execute authority (*X) to a user with QSECOFR authority. Different users
can get different results in certain situations, even though both users appear to
have the same access to the same files. This is important to know when running
shell scripts using the Qshell Interpreter or java.Runtime.exec().
For example, one user writes a Java program that uses java.Runtime.exec() to call a
shell script, then tests it using a userid with QSECOFR authority. If the file mode
of the shell script has read and write authority (*RW), the integrated file system
allows the userid with QSECOFR authority to run it. However, a non-QSECOFR
authority user could try to run the same Java program, and the integrated file
system would tell the java.Runtime.exec() code that the shell script is not
executable, because *X is missing. In this case, java.Runtime.exec() throws an input
and output exception.
For more information, see the OS/400 Program and CL Command APIs, SC41-5870
You store Java program files in the integrated file system. You encode the character
or text program files in the integrated file system in the code page that is specified
by the Java system property “file.encoding.” This includes Java source code files
Program data input or output that uses any stream class, other than these four:
java.io.InputStreamReader, java.io.FileReader, java.io.OutputStreamWriter, or
java.io.FileWriter, is considered binary data and performs no character code page
conversion. Program data input or output that uses the above four stream classes
is considered as character data, and performs an appropriate character code page
conversion. Character code page conversion depends on the source or target of the
data.
Data to or from the DB2/400 database, through the JDBC APIs, converts to or from
the CCSID of the AS/400 database.
Data that is transferred to or from other programs through Java Native Interface
does not get converted.
You can also see Internationalization by Sun Microsystems, Inc. for more
information.
For more information about JNDI, see Java Naming and Directory interface by Sun
The debugger runs in the same multi-thread capable job as the Java virtual
machine. The debugger uses Java Native Interface (JNI) Invocation APIs to create a
Java virtual machine. It then places a hook at the beginning of a user class main
method and calls the main method. When the main method begins, the hook is hit
and debugging begins. Typical debug facilities are available, such as setting
breakpoints, stepping, displaying variables, and changing variables.
The debugger handles communication between the job where the Java virtual
machine is running and a job handling the user interface. This user interface is
either on your AS/400 or another system.
A service program, called QJVAJVMDI that resides in the QSYS library, supports
the JVMDI functions.
For more information about JVMDI, see Java Virtual Machine Debugger Interface
by Sun Microsystems, Inc.
Java differs from a traditional language, like C++, in how it compiles and runs. In
a traditional programming environment, you write and compile source code of a
program into object code for a specific hardware and operating system. The object
code binds to other object code modules to create a running program. The
executable code is specific for a particular set of computer hardware and does not
run on other systems without modification. This graphic illustrates the traditional
language deployment environment.
The Java environment differs from other programming environments in that the
Java compiler does not generate machine code for a hardware-specific instruction
set. Instead, the Java compiler converts Java source code into Java virtual machine
instructions, which Java class files store. You can use either ZIP files or JAR files to
store class files. The class file does not target a specific hardware platform, but
instead targets the Java virtual machine architecture.
Java is a “multithreaded” programming language, thus more than one thread may
be running within the Java virtual machine at one time. Java threads provide a
way for a Java program to perform multiple tasks at the same time.
Applications are stand-alone programs that do not require the use of a browser.
Java applications run by starting the Java interpreter from the command line and
by specifying the file that contains the compiled application. Applications usually
reside on the system on which they are deployed. Applications access resources on
the system, and the Java “sandbox” security model does not restrict applications.
A Java applet is a small computer program that you write in Java and run inside
of a Java-compatible browser or appletviewer. A Hypertext Markup Language
(HTML) web document can include a reference to the system on which the applet
resides. At runtime, the server downloads the applet from the server onto the
target system. On the target system, the applet is restricted from accessing local
system resources unless authorization has been explicitly granted.
Note: Java applications are not restricted; only applets are restricted. Applications
can freely access system resources and use native methods. Most AS/400
Developer Kit for Java programs are applications.
You can use the Create Java Program (CRTJVAPGM) command to ensure that the
code meets the safety requirements that the Java runtime imposes to verify the
bytecodes. This includes enforcing type restrictions, checking data conversions,
ensuring that parameter stack overflows or underflows will not occur, and
checking for access violations. However, you do not need to explicitly verify the
bytecodes. If you do not use the CRTJVAPGM command in advance, then the
checks occur during the first use of a class. Once the bytecodes are verified, the
interpreter decodes the bytecodes and runs the machine instructions that are
needed to carry out the desired operations.
In addition to loading and running the bytecodes, the Java virtual machine
includes a garbage collector that manages memory. Garbage collection runs at the
same time as the loading and interpretation of the bytecodes.
JAR is the only archive format that is cross-platform. JAR is also the only format
that handles audio files and image files, as well as class files. JAR is an open
standard, fully extendable format that is written in Java.
The JAR format also supports compression, which reduces the size of the file and
decreases download time. Additionally, an applet author may digitally sign
individual entries in a JAR file to authenticate their origin.
Java interpreter
The Java interpreter is the part of the Java virtual machine that interprets Java class
files for a particular hardware platform. The Java interpreter decodes each
bytecode and runs a series of machine instructions for that bytecode.
Java threads
A thread is a single independent stream that runs within a program. Java is a
multithreaded programming language, so more than one thread may be running
within the Java virtual machine at one time. Java threads provide a way for a Java
program to perform multiple tasks at the same time. A thread is essentially a flow
of control in a program.
Threads are a modern programming construct that are used to support concurrent
programs and to improve the performance and scalability of applications. Most
programming languages support threads through the use of add-in programming
libraries. Java supports threads as built-in application program interfaces (API).
Note: The use of threads provides the support to increase the interactivity,
meaning a shorter wait at the keyboard because more things are running in
parallel. But, the program is not necessarily more interactive just because it has
threads.
Threads are the mechanism for waiting on long running interactions, while still
allowing the program to handle other work. Threads are the ability to support
multiple flows through the same code stream. They are sometimes called
“lightweight processes”. The Java language includes direct support for threads.
But, by design, it does not support asynchronous non-blocking input and output
with interrupts or multiple wait.
Threads can also use asynchronous methods. When you call a second method, you
do not have to wait for the first method to complete before the second method
continues with its own activity.
There are also many reasons not to use threads. If a program uses inherently
sequential logic, one thread can accomplish the entire sequence. Using multiple
threads in such a case results in a complex program with no benefits. There is
considerable work in creating and starting a thread. If an operation involves only a
few statements, it is faster to handle it in a single thread. This can be true even
when the operation is conceptually asynchronous. When multiple threads share
objects, the objects must synchronize to coordinate thread access and maintain
consistency. Synchronization adds complexity to a program, is difficult to tune for
optimal performance, and can be a source of programming errors.
The JDK enables programmers to write applications that are developed once and
run anywhere on any Java virtual machine. Java applications that are developed
with the JDK on one system can be used on another system without changing or
recompiling the code. The Java class files are portable to any standard Java virtual
machine.
To find more information about the current JDK, check the version of the AS/400
Developer Kit for Java on your AS/400.
You can check the version of the default AS/400 Developer Kit for Java Java
virtual machine on your AS/400 by entering either of the following:
v java -version on the Qshell command prompt.
v RUNJVA CLASS(*VERSION) on the CL command line.
Then, look for the same version of Sun Microsystems, Inc. JDK at The Source for
See Support for multiple Java Development Kits (JDKs) for more information about
using different Java virtual machines.
Java packages
A Java package is a way of grouping related classes and interfaces in Java. Java
packages are similar to class libraries that are available in other languages.
The Java packages, which provide the Java APIs, are available as part of Sun
Microsystems, Inc. Java Development Kit (JDK).
Package Contents
java.applet Applet classes
java.awt Graphics, window, and graphical user
interface (GUI) classes
java.awt.datatransfer Data transfer classes
java.awt.event Event processing classes and interfaces
java.awt.image Image processing classes
java.awt.peer GUI interfaces for platform independence
java.beans JavaBeans component model API
java.io Input and output classes
java.lang Core language classes
java.lang.reflect Reflection API classes
java.math Arbitrary precision arithmetic
java.net Networking classes
java.rmi Remote Method Invocation classes
java.rmi.dgc RMI-related classes
java.rmi.registry RMI-related classes
java.rmi.server RMI-related classes
java.security Security classes
java.security.acl Security-related classes
java.security.interfaces Security-related classes
java.sql JDBC SQL API for database classes
java.text Internationalization classes
java.util Data types
java.util.zip Compression and decompression classes
For more information about the Java APIs by Sun Microsystems, Inc., see the Sun
Microsystems, Inc. API Users Guide.
Once you decide that a native method is required, it may have to interoperate with
the Java virtual machine where it runs. The Java Native Interface (JNI) facilitates
this interoperability in a platform-neutral way.
The JNI is a set of interfaces that permit a native method to interoperate with the
Java virtual machine in numerous ways. For example, the JNI includes interfaces
that create new objects and call methods, get fields and set fields, process
exceptions, and manipulate strings and arrays.
For a complete description of the JNI, refer to the Java Native Interface by Sun
If you have prior Java programming experience, you may be more comfortable
using the Qshell Interpreter Java tools, because they are similar to the tools that
you would use with Sun Microsystems, Inc. Java Development Kit. See Qshell
Interpreter for information about using the Qshell environment.
If you are an AS/400 programmer, you may want to use the CL commands for
Java that are typical to the AS/400 server environment. Read on for more
information about using CL commands and Operations Navigator commands.
You can use any of these commands and tools with the AS/400 Developer Kit for
Java:
v The Qshell environment includes the Java development tools that are typically
required for program development.
v The CL environment contains the CL commands for optimizing and managing
Java programs.
v The Operations Navigator commands also create and run optimized Java
programs.
Java tools that are supported by the AS/400 Developer Kit for Java
The AS/400 Developer Kit for Java supports these tools.
v Java ajar tool
v Java appletviewer tool
v Java extcheck tool
v Java jar tool
v Java jarsigner tool
v Java javac tool
v Java javadoc tool
v Java javah tool
v Java javakey tool
v Java javap tool
v Java keytool
v Java native2ascii tool
v Java policytool
v Java rmic tool
v Java rmid tool
v Java rmiregistry tool
v Java serialver tool
You can start the Qshell Interpreter by using the Start Qshell (STRQSH or QSH)
command. When the Qshell Interpreter is running, a QSH Command Entry display
appears. All output and messages from Java tools and programs that run under
Qshell appear in this display. Any input to a Java program is also read from this
display. See Java command in Qshell for more details.
Note: Functions of AS/400 command entry are not available directly from within
the Qshell. To get a command entry, press F21 (CL command entry).
If you need a ZIP interface or UNZIP interface, use the ajar tool instead of the jar
tool.
The ajar tool lists the contents of JAR files, extracts from JAR files, creates new
JAR files, and supports many of the ZIP formats just as the jar tool does.
Additionally, the ajar tool supports adding and deleting files in existing JAR files.
The ajar tool is available using the Qshell Interpreter. For more details, see ajar -
Alternative Java archive.
The appletviewer tool is available using the Qshell Interpreter. You need to use
Remote Abstract Window Toolkit to run the appletviewer tool. See Running
the Java appletviewer tool with Remote AWT for information about how to set up
Remote AWT to use the appletviewer tool.
For more information about the appletviewer tool, see the appletviewer tool by
Sun Microsystems, Inc.
For example, if you use the sun.applet.AppletViewer class and run example1.html
out of the TicTacToe directory, the command line should look like this:
JAVA CLASS(sun.applet.AppletViewer) PARM('example1.html') CLASSPATH('/TicTacToe')
PROP((RmtAwtServer '1.1.11.11') (os400.class.path.rawt 1)(java version 1.2))
If you use the appletviewer tool in the Qshell Interpreter and run example1.html
out of the TicTacToe directory, the commands should look like this:
qsh “enter”
cd TicTacToe “enter”
Appletviewer -J-DRmtAwtServer=1.1.11.11 -J-Dos400.class.path.rawt=1 -J-Djava.version=1.2 example1.
For more information about the extcheck tool, see the extcheck tool by Sun
Microsystems, Inc.
For an alternative interface to the jar tool, see the ajar tool for creating and
manipulating JAR files.
For more information about AS/400 file systems, see the OS/400 Integrated File
System Introduction or files in the integrated file system.
For more information about the jar tool, see the jar tool by Sun Microsystems, Inc.
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 59
[ Information Center Home Page | Feedback [ Legal | AS/400 Glossary ]
]
For more information about the jarsigner tool, see the jarsigner tool by Sun
Microsystems, Inc.
If you have JDK 1.1.x installed on AS/400 as your default, but you need to run the
1.2 version of the java command, enter this command:
javac -djava.version=1.2 <my_dir> MyProgram.java
For more information about the javac tool, see the javac tool by Sun Microsystems,
Inc.
For more information about the javadoc tool, see the javadoc tool by Sun
Microsystems, Inc.
Note: Writing native methods means that your application is not 100% pure Java.
It also means that your application is not directly portable across platforms. Native
methods are, by nature, platform or system specific. Using native methods may
increase your development and maintenance costs for your applications.
The javah tool is available using the Qshell Interpreter. It reads a Java class file
and creates a C-language header file in the current working directory. The header
file that is written is an AS/400 Stream File (STMF). It must be copied to a file
member before it can be included in a C program on AS/400.
The javah tool is compatible with the tool that is provided by Sun Microsystems,
Inc. If these options are specified; however, AS/400 ignores them.
-td The javah tool on AS/400 does not require a temporary directory.
-stubs Java on AS/400 only supports the Java Native Interface (JNI) form of
native methods. Stubs were only required for the pre-JNI form of native
methods.
-trace Relates to the .c stub file output, which Java on AS/400 does not support.
-v Not supported.
Note:The -jni option must always be specified. The AS/400 system does not
support native method implementations prior to JNI.
For more information about the javah tool, see the javah tool by Sun Microsystems,
Inc.
In Java 2 Software Development Kit (J2SDK), Standard Edition, version 1.2, the
javakey tool is obsolete. Due to bugs in JDK versions 1.1.x, code that is signed
using the 1.1.x javakey tool is recognized as unsigned in the J2SDK, version 1.2. If
you sign code using J2SDK, version 1.2, it is recognized as unsigned on JDK 1.1.x
versions.
Note: The AS/400 secure sockets layer (SSL) support cannot access keys created by
this tool. Instead, you must use the certificate and key containers that are
integrated into the AS/400 and created or imported with the Digital Certificate
Manager. See making a Java application secure with the secure sockets layer for
more information.
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 61
Applet packaging and applet signing is dependent on your browser. Check your
browser documentation to ensure that your browser is compatible with the Java
JAR file format and javakey applet signing.
Note: The files that are created by the javakey tool contain sensitive information.
Appropriate integrated file system security measures protect the public and private
key files.
For more information about AS/400 file systems, see the OS/400 Integrated File
System Introduction or files in the integrated file system.
For more information about the javakey tool, see the javakey tool by Sun
Microsystems, Inc.
It is compatible with the javap tool that is supplied by Sun Microsystems, Inc. with
a few exceptions.
-b This option is ignored. Backward compatibility is not required, because
Java on AS/400 only supports Java Development Kit (JDK) 1.1.4 and later.
-p On AS/400, -p is not a valid option. You must spell out -private.
-verify
This option is ignored. The javap tool does not do verification on AS/400.
Note:The use of the javap tool to disassemble classes may violate the license
agreement for those classes. Consult the license agreement for the classes before
using the javap tool.
For more information about the javap tool, see the javap tool by Sun
Microsystems, Inc.
Java keytool
In Java 2 SDK (J2SDK), Standard Edition, version 1.2, the keytool creates
public and private key pairs, self-signed certificates, and manage keystores. In
J2SDK, the jarsigner and keytool tools replace the javakey tool. It is compatible
with the keytool that is supplied by Sun Microsystems, Inc.
For more information about the native2ascii tool, see the native2ascii tool by Sun
Microsystems, Inc.
Java policytool
In Java 2 SDK, Standard Edition, version 1.2, the policytool creates and
changes the external policy configuration files that define the Java security policy
of your installation. It is compatible with the policytool that is supplied by Sun
Microsystems, Inc.
The policytool is a graphical user interface (GUI) tool available using the Qshell
Interpreter and the Remote Abstract Window Toolkit. See AS/400 Developer Kit
for Java Remote Abstract Window Toolkit for more information.
For more information about the policytool, see the policytool by Sun
Microsystems, Inc.
For more information about the rmic tool, see the rmic tool by Sun Microsystems,
Inc.
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 63
Java rmid tool
In Java 2 SDK (J2SDK), Standard Edition, version 1.2, the rmid tool starts the
activation system daemon, so objects can be registered and activated in a Java
virtual machine. It is compatible with the rmid tool that is supplied by Sun
Microsystems, Inc.
For more information about the rmid tool, see the rmid tool by Sun Microsystems,
Inc.
For more information about the rmiregistry tool, see the rmiregistry tool by Sun
Microsystems, Inc.
For more information about the serialver tool, see the serialver tool by Sun
Microsystems, Inc.
The AS/400 Developer Kit for Java ignores these options of the java command in
Qshell.
Option Description
-cs Not supported.
-checksource Not supported.
-debug Supported by the AS/400 internal debugger.
-noasyncgc Garbage collection is always running with
the AS/400 Developer Kit for Java.
-noclassgc Garbage collection is always running with
the AS/400 Developer Kit for Java.
-prof AS/400 has its own performance tools.
-ss Not applicable on AS/400.
-oss Not applicable on AS/400.
-t AS/400 uses its own trace function.
-verify Always verify on AS/400.
-verifyremote Always verify on AS/400.
-noverify Always verify on AS/400.
On AS/400, the -classpath option does not override the default classpath. Instead,
it is appended to the system default classpath. The -classpath option does
override the CLASSPATH environment variable.
The java command in Qshell supports new options for AS/400. These are the new
options that are supported.
Option Description
-secure Checks for public write access to directories
in the CLASSPATH.
-gcfrq Specifies the garbage collection frequency.
-gcpty Specifies the garbage collection priority.
-opt Specifies the optimization level.
-verbosegc A message is displayed for each garbage
collection sweep.
For more information about the java command in Qshell, see the java tool by Sun
Microsystems, Inc.
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 65
CL commands that are supported by Java
The AS/400 Developer Kit for Java supports the these CL commands.
v Create Java Program (CRTJVAPGM) command creates a Java program on
AS/400 from a Java class file, ZIP file, or JAR file.
v Change Java Program (CHGJVAPGM) command changes the attributes of a Java
program.
v JAVA command and Run Java (RUNJVA) command run AS/400 Java programs.
v Delete Java Program (DLTJVAPGM) command deletes an AS/400 Java program
that is associated with a Java class file, ZIP file, or JAR file.
book.
Syntax:
CRTJVAPGM Command
(P)
>>—CRTJVAPGM—CLSF(—.-class-file-name-.—)————————————————>
'-JAR-file-name—-'
>—.———————————————.—.———————————-.———————>
| .-10————-. | | .-*YES-. |
'-OPTIMIZE(—+-*INTERPRET-+—)-' '-REPLACE(—'-*NO—'—)-'
|-20————-|
|-30————-|
'-40————-'
>—.———————————————-.—.————————————.——————>
| .-*NONE———. | | .-*USER—. |
'-ENBPFRCOL(—+-*ENTRYEXIT-+—)-' '-USRPRF(—'-*OWNER-'—)-'
'-*FULL———'
>—.————————————-.—.————————————.—————————>
| .-*NO—. | | .-*NONE-. |
'-USEADPAUT(—'-*YES-'—)-' '-SUBTREE(—'-*ALL—'—)-'
>—.————————————————-.———————————————————>
| .-*OPTIMIZE———. |
'-LICOPT(—'-options-string-'—)—'
Notes: (P) All parameters preceding this point can be specified positionally.
Required parameters:
CLSF
The CLSF parameter specifies the class file name or JAR file name from
which you create Java programs on AS/400. One or more directory names
may qualify the class file name.
For the class-file-name, specify the name of the class file or a pattern for
identifying the name of the class files that are used. Specify a pattern in
the last part of the name. An asterisk matches any number of characters,
and a question mark matches a single character. Enclose the name in
apostrophes if it is qualified or contains a pattern. An example of a
qualified class file name is:
'/directory1/directory2/myclassname.class'
For the JAR-file-name, specify the name of the JAR file or a pattern for
identifying the name of the JAR files that are used. A file is a JAR file if it
ends with .jar or .zip. Specify a pattern in the last part of the name. An
asterisk matches any number of characters, and a question mark matches a
single character. Enclose the name in apostrophes if it is qualified or
contains a pattern. An example of a qualified JAR file name is:
'/directory1/directory2/myappname.jar'
Optional parameters:
OPTIMIZE
The OPTIMIZE parameter for the CRTJVAPGM command specifies the
optimization level of the AS/400 Java program that attaches to the class
file object or JAR file object. If you use the OPTIMIZE(*INTERPRET)
parameter, the resulting Java program is verified and converted to an
internal form. It is then interpreted when it runs. For the other
optimization levels, the internal form includes AS/400 machine
instructions. These AS/400 machine instructions are optimized based on
the specified optimization level. The AS/400 directly runs the machine
instructions when the program runs.
When you specify OPTIMIZE(*INTERPRET), Java programs are smaller,
but run slower than Java programs that are created with higher
optimization levels. As you increase the optimization level beyond 10, Java
program performance gradually improves, but the time that is required to
create the Java program increases. It also makes it more difficult to debug
the Java program as you increase the optimization level.
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 67
Typically, *INTERPRET is a good option during development and early
testing, because quick edit, compile turnaround, and quality debug
functions are important. As the program moves toward release, the level of
optimization often increases.
This list shows how the optimization levels differ and what they do:
10 The Java program contains a transformed version of the class file
bytecodes, but has only minimal additional compiler optimization.
You can display and change variables while debugging.
20 The Java program contains a compiled version of the class file
bytecodes and performs additional compiler optimization. You can
display, but not change variables while debugging.
30 The Java program contains a compiled version of the class file
bytecodes and performs more compiler optimization than
optimization level 20. Debugging at higher optimization levels is
more difficult, because optimization reduces the ability to stop at
precise points in the code and display program variables. You can
display, but not change variables while debugging. The values that
are presented may not be the current value of the variable.
40 The Java program contains a compiled version of the class file
bytecodes and performs more compiler optimization than
optimization level 30. In addition, it includes optimization that
disables call and instruction tracing. Optimization level 40 includes
cross-class optimizations. In a small number of cases, the order in
which static initializers are run for unrelated classes (not related by
inheritance nor containment) may be different than outlined in the
static initialization specification. In addition, it includes
optimization that disables call and instruction tracing.
Note: If your Java program fails to optimize or throws an
exception at optimization level 40, use optimization level 30.
*INTERPRET
The Java programs that you create are not optimized. When you
start the program, it interprets the class file bytecode. You can
display and change variables while debugging.
REPLACE
The REPLACE parameter specifies whether a new Java program replaces
an existing Java program that is associated with the class file.
*YES Forces all of the Java programs that are associated with the class
file or JAR file to be re-created for your selected optimization level.
For large JAR files, this could be time consuming, but it creates the
highest performing code generation and uses the minimum
amount of space on the disk.
*NO Recreates the minimum number of required Java programs that are
associated with the class file or JAR file. If classes have been
modified, no Java program is associated with one or more classes.
If the Java program is at a different optimization level than you
had specified with the OPTIMIZE parameter, new Java programs
are created.
USRPRF
The USRPRF parameter specifies whether the authority checking that is
done while the program is running should include only the user who is
running the program (*USER) or both the user who is running the program
and the program owner (*OWNER). The user profiles of the program user,
or both the program user and the program owner control which objects the
program can use. This includes the authority that the program has for each
object. Only the program owner or program user with QSECOFR authority
can change the user profile attribute of an existing Java program.
Note: Integrated file system functions that the program might use, such as
File.delete(), do not recognize adopted authority. Integrated file system
functions only use the authority from the user who is running the
program.
*USER
The program runs under the user profile of the program user.
*OWNER
You use the user profiles of both the program owner and program
user when processing the program. You can use the collective sets
of object authority in both user profiles to find and access objects
during program processing. Authority from the group profile of
the owning user profile is not used.
USEADPAUT
The USEADPAUT parameter specifies whether or not you use program
adopted authority from previous programs in the call stack as a source of
authority when the program is running.
Note: Integrated file system functions that the program might use, such as
File.delete(), do not recognize adopted authority. Integrated file system
functions only use the authority from the user who is running the
program.
*NO Do not use program adopted authority from previous call levels
when the program is running. If an authorization list is specified
for the QUSEADPAUT system value and the user performing
CRTJVAPGM is not included in that authorization list, then the
value *NO is automatically supplied for this parameter.
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 69
*YES Use program adopted authority from previous call levels when the
program is running.
LICOPT
The LICOPT parameter specifies one or more licensed internal code
compile-time optimization options. Only advanced programmers, who
understand the potential benefits and drawbacks of each selected type of
optimization, should use this parameter. For a listing of recognized strings
for the LICOPT parameter, see LICOPT parameter strings.
Note:You should contact your service representative for more information
on how to use these optimizations.
*OPTIMIZE
The *OPTIMIZE option uses the set of compile-time optimizations,
which are implicitly associated with the optimization level that is
specified on the OPTIMIZE parameter. If you specify
OPTIMIZE(*INTERPRET), no compile-time optimizations are
performed.
’Licensed-Internal-Code-options-string’
Use the selected licensed internal code compile-time optimization
options when creating the Java program object. Certain
optimization options may reduce your ability to debug the Java
program that was created.
SUBTREE
The SUBTREE parameter specifies whether or not subdirectories are
processed when looking for files that match the CLSF keyword.
*NONE
Only the files that match the object name pattern are processed. No
subtrees are processed. If the directory has subdirectories, neither
the subdirectories nor the objects on the subdirectories are
processed.
*ALL The entire subtree of the path that is specified in CLSF is processed
to create Java programs for files that match the name that was
specified on the CLSF parameter.
TGTRLS
The TGTRLS parameter specifies the release of the operating system on
which you intend to use the object that is being created. When specifying
the target-release, you use the VxRxMx format to specify the release. Vx is
the version. Rx is the release, and Mx is the modification level. For
example, V4R5M0 is version 4, release 5, modification level 0. Valid values
depend on the current version, release, and modification level. These valid
values change with each new release.
*CURRENT
The object is used on the release of the operating system that is
For more performance information, see tuning Java program performance with the
AS/400 Developer Kit for Java.
See Example: Create Java Program (CRTJVAPGM) command for an example that
uses the CRTJVAPGM command.
String Description
AllFieldsVolatile If set, treats all fields as volatile.
NoAllFieldsVolatile Is not set; does not treat all fields as volatile.
AllowBindingToLoadedClasses Indicates that temporary class representations
that were created as a result of defineClass
calls within a running Java virtual machine
may be tightly bound to other class
representations within the same Java virtual
machine.
NoAllowBindingToLoadedClasses Indicates that temporary class representations
that were created as a result of defineClass
calls within a running Java virtual machine
may not be tightly bound to other class
representations within the same Java virtual
machine.
AllowBindingWithinJar Indicates that class representations within a
ZIP file or JAR file may be tightly bound to
other class representations within the same
ZIP file or JAR file.
NoAllowBindingWithinJar Indicates that class representations within a
ZIP file or JAR file may not be tightly bound
to other class representations within the same
ZIP file or JAR file.
AllowInlining Tells the translator that it is permitted to
inline local methods. This is the default for
optimization levels 30 and 40.
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 71
String Description
NoAllowInlining Does not tell the translator that it is
permitted to inline local methods.
AssumeUnknownFieldsNonvolatile When the attributes of a field in an external
class cannot be determined, this parameter
generates code by assuming that the field is
non-volatile.
NoAssumeUnknownFieldsNonvolatile When the attributes of a field in an external
class cannot be determined, this parameter
generates code by assuming that the field is
volatile.
BindErrorHandling Specifies what action should be taken if, as a
result of honoring the
AssumeUnknownFieldsNonvolatile,
PreresolveExtRef, or PreLoadExtRef Licensed
Internal Code option, the Java virtual
machine class loader detects that a class
representation contains method
representations, which cannot be used in the
current context.
BindInit Use bound call to local init methods.
NoBindInit Do not use bound call to local init methods.
BindSpecial Use bound call to local special methods.
NoBindSpecial Do not use bound call to local special
methods.
BindStatic Use bound call to local static methods.
NoBindStatic Do not use bound call to local static
methods.
BindTrivialFields Bind trivial field references during program
creation.
NoBindTrivialFields Resolve field references at first touch.
BindVirtual Use bound call to local final virtual methods.
NoBindVirtual Do not use bound call to local final virtual
methods.
DeferResolveOnClass Takes a string parameter that is presumed to
be the name of a class (for example,
java.lang.Integer). When you set
PreresolveExtRef to optimization level 40,
classes that are specified with
DeferResolveOnClass are not in the
preresolve operation. This is useful if some
classes in unused paths in the code are not in
the CLASSPATH. It allows you to use
optimization level 40 regardless of this by
specifying a
“DeferResolveOnClass=’somepath.someclass’”
for each missing class. Multiple
DeferResolveOnClass entries are allowed.
DevirtualizeFinalJDK Allows CRTJVAPGM to use knowledge of
the standard JDK to devirtualize calls to
those JDK methods that are known to be
final methods or members of final classes. It
is the default at optimization levels 30 and
40.
NoDevirtualizeFinalJDK Does not allow CRTJVAPGM to use
knowledge of the standard JDK to
devirtualize calls to those JDK methods that
are known to be final methods or members
of final classes.
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 73
String Description
NoInlineTransFloat No inline transcendental float/double
methods.
PreloadExtRef Indicates that referenced classes may be
pre-loaded (without class initialization) upon
method entry.
NoPreloadExtRef Indicates that referenced classes may not be
pre-loaded upon method entry. However, the
PreresolveExtRef parameter overrides this
setting and causes referenced classes to be
pre-loaded and initialized. .
PreresolveExtRef Preresolve referenced methods at method
entry.
NoPreresolveExtRef Resolve method references at first touch. Use
to resolve “class not found” exceptions on
programs that run on other machines.
ShortCktAthrow If set, attempt to short-circuit athrows.
NoShortCktAthrow Is not set; does not attempt to short-circuit
athrows.
ShortCktExSubclasses If set, recognize some subclasses of Exception
and short-circuit them directly.
NoShortCktExSubclasses Is not set; does not recognize some
subclasses of Exception and short-circuit
them directly.
The double asterisk (**) signifies that these strings require a numerical value for
input in the syntax of stringname=number (with no spaces in between).
This example is the same as Example 1; except that the program is optimized. It is
created with OPTIMIZE(40), so the program contains compiled machine
instructions that run when the Java program starts.
See the Create Java Program (CRTJVAPGM) command for syntax diagram and
parameter details.
You can recreate Java programs if the attributes that are specified differ from those
of the current programs or if you specify MERGE(*YES). The CHGJVAPGM
command does not create Java programs for class files, or classes within JAR files
that do not have attached Java programs. A Java program is created dynamically
when a class is loaded without a current Java program attached. There may be
classes in a JAR file from which no Java programs have been created. You can use
the Create Java Program (CRTJVAPGM) command to create Java programs from
these classes. The CHGJVAPGM command replaces existing Java programs only.
Syntax:
CHGJVAPGM Command
(P)
>>—CHGJVAPGM—CLSF(—.-class-file-name-.—)————————————————>
'-JAR-file-name—-'
>—.———————————————.—.———————————————-.———>
| .-SAME———-. | | .-*SAME———. |
'-OPTIMIZE(—+-*INTERPRET-+—)-' '-ENBPFRCOL(—+-*NONE———+—)-'
|-10————-| |-*ENTRYEXIT-|
|-20————-| '-*FULL———'
|-30————-|
'-40————-'
>—.——————————-.—.————————————.———————————>
| .-*RPL-. | | .-*NONE-. |
'-MERGE(—'-*YES-'—)-' '-SUBTREE(—'-*ALL—'—)-'
>—.————————————————.———————————————————->
| .-*SAME—————. |
'-LICOPT(—+-*OPTIMIZE———+—)-'
'-options-string-'
Notes: (P) All parameters preceding this point can be specified positionally.
Required parameter:
CLSF
The CLSF parameter specifies the class file name or JAR file name that are
attached to the Java programs to change. One or more directory names
may qualify the class file name.
For the class-file-name, specify the name of the class file or a pattern for
identifying the name of the class files that are used. Specify a pattern in
the last part of the name. An asterisk matches any number of characters,
and a question mark matches a single character. Enclose the name in
apostrophes if it is qualified or contains a pattern. An example of a
qualified class file name is:
'/directory1/directory2/myclassname.class'
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 75
For the JAR-file-name, specify the name of the JAR file or a pattern for
identifying the name of the JAR files that are used. A file is a JAR file if it
ends with .jar or .zip. Specify a pattern in the last part of the name. An
asterisk matches any number of characters, and a question mark matches a
single character. Enclose the name in apostrophes if it is qualified or
contains a pattern. An example of a qualified JAR file name is:
'/directory1/directory2/myappname.jar'
Optional parameters:
OPTIMIZE
The OPTIMIZE parameter for the CHGJVAPGM command specifies the
optimization level of each AS/400 Java program that is attached to the
class object or the JAR file object. If you use the OPTIMIZE(*INTERPRET)
parameter, the resulting Java program is verified and converted to an
internal form. It is then interpreted when it runs. For the other
optimization levels, the internal form includes AS/400 machine
instructions. These AS/400 machine instructions are optimized based on
the specified optimization level. The AS/400 directly runs the machine
instructions when the program runs.
OPTIMIZE(*INTERPRET) Java programs are smaller, but run slower than
Java programs that are created with higher optimization levels. As the
optimization level increases beyond 10, Java program performance
gradually improves, but the time that is required to create the Java
program increases. It also makes it more difficult to debug the Java
program as you increase the optimization level.
Typically, *INTERPRET is a good option during development and early
testing, because quick edit, compile turnaround, and quality debug
functions are important. As the program moves toward release, the level of
optimization often increases.
This list shows how the optimization levels differ and what they do:
*SAME
The value does not change.
10 The Java program contains a transformed version of the class file
bytecodes, but has only minimal additional compiler optimization.
You can display and change variables while debugging.
20 The Java program contains a compiled version of the class file
bytecodes and has additional compiler optimization. You can
display, but not change variables while debugging.
30 The Java program contains a compiled version of the class file
bytecodes and has more compiler optimization than optimization
level 20. Debugging at higher optimization levels is more difficult,
because optimization reduces the ability to stop at precise points in
the code and display program variables. You can display, but not
change variables while debugging. The values that are presented
may not be the current value of the variable.
40 The Java program contains a compiled version of the class file
bytecodes and has more compiler optimization than optimization
level 30. In addition, it includes optimization that disables call and
ENBPFRCOL
The ENBPFRCOL parameter specifies whether or not to enable the
collection of performance data.
*SAME
The value does not change.
*NONE
The collection of performance data is not enabled. No performance
data is collected.
*ENTRYEXIT
The performance data is collected for procedure entry and exit.
*FULL The performance data is collected for procedure entry and exit.
Performance data is also collected before and after calls to the
external procedures.
MERGE
The MERGE parameter specifies whether or not you merge Java programs,
which are attached to a JAR file, into the minimum number of Java
programs possible. This parameter is ignored if you are processing a Java
class file.
*RPL Specifies that you merge Java programs, which are attached to a
JAR file, only if the Java programs need to be re-created and
replaced, because other Java program attributes are being changed.
If no attributes are changed and no Java programs need to be
re-created and replaced, then no merging of Java programs occurs.
*YES You merge all Java programs, which are attached to a JAR file, into
the minimum number of Java programs possible to save space or
improve class loader time.
SUBTREE
The SUBTREE parameter specifies whether or not subdirectories are
processed when looking for files that match the CLSF keyword.
*NONE
Only the files that match the object name pattern are processed. No
subtrees are processed. If the directory has subdirectories, neither
the subdirectories nor the objects on the subdirectories are
processed.
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 77
*ALL The entire subtree of the path that is specified in CLSF is processed
to create Java programs for files that match the name that was
specified on the CLSF parameter.
LICOPT
The LICOPT parameter specifies one or more licensed internal code
compile-time optimization options. Only advanced programmers, who
understand the potential benefits and drawbacks of each selected type of
optimization, should use this parameter.
Note: You should contact your service representative for more information
on how to use these optimizations.
*SAME
The value does not change.
*OPTIMIZE
The *OPTIMIZE option uses the set of compile-time optimizations,
which are implicitly associated with the optimization level that is
specified on the OPTIMIZE parameter. If you specify
OPTIMIZE(*INTERPRET), no compile-time optimizations are
performed.
’options-string’
See LICOPT parameter strings for a listing of recognized strings.
For more performance information, see tuning Java program performance with the
AS/400 Developer Kit for Java.
See Example: Change Java Program (CHGJVAPGM) command for an example that
uses the CHGJVAPGM command.
This example is the same as Example 1, except that the program is optimized. It is
changed with OPTIMIZE(10), so the program contains compiled machine
instructions that run when the Java program starts.
See the Change Java Program (CHGJVAPGM) command for syntax diagram and
parameter details.
JAVA command
The JAVA command functions exactly the same as the Run Java (RUNJVA)
command. You can use them interchangeably. See Run Java (RUNJVA) command
for information and parameters that you can use with the JAVA command.
The Run Java (RUNJVA) command runs the AS/400 Java program, which is
associated with the Java class that is specified. If a Java program does not exist,
one is created and associated with the class file.
Syntax:
RUNJVA Command
>>—RUNJVA—CLASS(—.-class-name—.—)———————————————————>
| (1)|
'-*VERSION——'
(P)
>—.———————————————————————————————————->
| .-*NONE—————————. |
| | <————————-> (2)| |
'-PARM(—'—-parameter-value———'—)-'
>—.———————————————-.—.—————————————.—————>
| .-*ENVVAR——. | | .-*WARN—-. |
'-CLASSPATH(—'-class-path-'—)-' '-CHKPATH(—+-*SECURE-+—)-'
'-*IGNORE-'
>—.———————————————.—.———————————————.———->
| .-10————-. | | .-*OPTIMIZE-. |
'-OPTIMIZE(—+-*INTERPRET-+—)-' '-INTERPRET(—+-*NO———-+—)-'
+-*JIT———-+ |-*YES———|
+-20————-+ '-*JIT———'
+-30————-+
'-40————-'
>—.——————————————————————————-.—————————>
| .-*NONE————————————————-. |
| | <————————————————> (3)| |
'-PROP(—'—-property-name—property-value———-'—)-'
>—.———————————————————————————.—————————>
| .-*NOMAX———————————————-. |
'-GCHMAX(—'-garbage-collection-heap-maximum-size-'—)-'
>—.———————————————————————————.—————————>
| .-*2048————————————————. |
'-GCHINL(—'-garbage-collection-heap-initial-size-'—)-'
>—.—————————————————————————-.——————————->
| .-50————————————————-. |
'-GCFRQ(—'-garbage-collection-frequency-value-'—)-'
>—.——————————.—.———————————————————.————-><
| .-20-. | | .-*NONE————————. |
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 79
'-GCPTY(—+-30-+—-)-' | | <———————-> (4)| |
'-10-' '-OPTION(—'—.-*DEBUG——-.———'—)-'
|-*VERBOSE—-|
|-*VERBOSEGC-|
'-*NOCLASSGC-'
Required parameters:
CLASS
The CLASS parameter specifies the class name that is to be run. One or
more package names may qualify the class name. Follow each package
name with a period. For example, CLASS(’pkg1.pkg2.myclass’) identifies a
class that is qualified by two package names.
For class-name, specify the name of the class that runs.
Optional parameters:
PARM
The PARM parameter specifies one or more parameter values that are
passed to the Java program. You may specify a maximum of 200 parameter
values.
For parameter-value, specify the parameters to pass to the Java program.
CLASSPATH
The CLASSPATH parameter specifies the path that is used to locate classes.
Colons separate the directories.
The classpath locates classes. An example classpath:
'/directory1/directory2:/QIBM/ProdData/Java400'
OPTIMIZE
The OPTIMIZE parameter specifies the optimization level of the AS/400
Java program that is used if no Java program has ever been associated
with the Java class. Optimization is a time consuming operation, so
programs run slowly the first time that they are optimized if you use the
RUNJVA command instead of the CRTJVAPGM command. However,
subsequent runs use the optimized form, so optimization is a one-time
cost. This is true for class files, JAR files, and ZIP files.
The effect of the OPTIMIZE parameter depends on the current
optimization level of the program. The current optimization level results
from either the previous use of the RUNJVA command or the CRTJVAPGM
command.
If the program has never run on AS/400, and no previous CRTJVAPGM
command has run, then the optimization level that is selected is used
before the program runs. This optimization level is stored in the class file,
JAR file, or ZIP file.
If the RUNJVA command or CRTJVAPGM command has been run against
the program, then the OPTIMIZE parameter on the RUNJVA command has
no effect. One exception is the OPTIMIZE(*INTERPRET) parameter. This
parameter forces all of the loaded Java classes to run interpretively
regardless of the OPTIMIZE value of the associated Java program.
If you want to change the level of optimization of a program that has been
previously optimized, use the CRTJVAPGM command or CHGJVAPGM
command. Using the RUNJVA command does not create the desired
optimization level. Instead, it uses the saved value that is associated with
the class file, JAR file, or ZIP file.
Note:The *INTERPRET parameter behaves this way to debug code that has
been previously optimized. It does not require that you delete your
program, create the program again for low optimization, debug it, and
then optimize it again.
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 81
If the OPTIMIZE(*INTERPRET) parameter is used, the resulting Java
program is verified and converted to an internal form. Then, it is
interpreted when it runs. For the other optimization levels, the internal
form includes AS/400 machine instructions. These AS/400 machine
instructions are optimized based on the specified optimization level. The
AS/400 directly runs the machine instructions when the program runs.
OPTIMIZE(*INTERPRET) Java programs are smaller, but run slower than
Java programs that are created using higher optimization levels. As the
optimization level increases beyond 10, Java program performance
gradually improves, but the time that is required to create the Java
program increases. It is also more difficult to debug the Java program.
Typically, *INTERPRET is a good option during development and early
testing, because quick edit, compile turnaround, and quality debug
functions are important. As the program moves toward release, the level of
optimization often increases.
This list shows how the optimization levels differ and what they do:
10 The Java program contains a transformed version of the class file
bytecodes, but has only minimal additional compiler optimization.
While debugging, you can display and change variables.
*INTERPRET
The Java program that is created does not contain machine specific
instructions. When the program starts, it is interpreted. You can
display and change variables while debugging.
*JIT No Java program that contains machine instruction sequences is
created. The class runs by using the Just-In-Time (JIT) compiler.
INTERPRET
The INTERPRET parameter specifies whether all Java class files should run
interpretively.
OPTIMIZE
Java class files run interpretively depending on the value that is
specified for the OPTIMIZE parameter. If OPTIMIZE(*INTERPRET)
is specified, all Java class files run interpretively. If another value is
PROP
The PROP parameter specifies a list of values to assign to Java system
properties. You can assign up to 100 properties.
The limit for the PROP parameter is 5000 characters each for name and
value.
*NONE
No properties are specified.
GCHMAX
The GCHMAX parameter specifies the maximum amount of memory in
kilobytes that the Java virtual machine can allocate. Normally, you should
use the default or set this value as large as possible. However, if you are
concerned about a program that uses all available memory, you can set
GCHMAX to a smaller value. The default value is system dependent and
model dependent.
If Java virtual machine memory allocation reaches GCHMAX, all other
Java virtual machine threads are stopped while garbage collection takes
place. If garbage collection cannot reduce the memory allocation, the Java
virtual machine stops.
*NOMAX
The garbage collection heap grows until all system resources are
gone. Then, a synchronous garbage collection starts to reclaim the
resources that are no longer in use. With *NOMAX, synchronous
garbage collection occurs only if all available heap storage has been
used.
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 83
GCHINL
The GCHINL parameter provides a suggested threshold for initial garbage
collection. If this value is equal to GCHMAX, then garbage collection does
not run until the amount of memory that is allocated by the Java virtual
machine approaches GCHMAX. Setting the value to a smaller value
triggers an earlier garbage collection. The default value is system
dependent and model dependent.
GCFRQ
Note: This parameter is no longer supported. It exists solely for
compatibility with releases earlier than Version 4 Release 3 Modification 0
of the AS/400 system.
The GCFRQ parameter provides a suggested garbage collection frequency.
It may or may not be honored depending on the system release and model.
Values between 0 and 100 are allowed for GCFRQ. The default parameter
is 50. A lower value means less frequent garbage collection. A higher value
means more frequent garbage collection.
GCPTY
Note: This parameter is no longer supported. It exists solely for
compatibility with releases earlier than Version 4 Release 3 Modification 0
of the AS/400 system.
The GCPTY parameter provides a suggested garbage collection priority. It
may or may not be honored depending on the system release and model.
The GCPTY parameter specifies the relative priority of the threads that run
garbage collection. The priority is relative to the default user Java threads.
Higher values indicate higher priority. A low priority garbage collection
thread is less likely to run, because other higher priority tasks are running.
In most cases, GCPTY should be set to the default (equal) value or the
higher priority value. Setting GCPTY to the lower priority value can inhibit
garbage collection and cause in all Java threads to be held while the
garbage collector frees storage.
20 The default parameter value is 20. This indicates that the garbage
collection thread has the same priority as default user Java threads.
30 The 30 priority gives garbage collection higher priority than default
user Java threads. Garbage collection is more likely to run.
10 The 10 priority gives garbage collection lower priority than default
user Java threads. Garbage collection is less likely to run.
OPTION
The OPTION parameter specifies special options that are used when a Java
class runs.
*NONE
No special options are used when a Java class runs.
*DEBUG
Allows the use of the AS/400 system debugger for the Java
program.
See Example: Using the Run Java (RUNJVA) command for an example that uses
the RUNJVA command.
See the Run Java (RUNJVA) command for syntax diagram and parameter details.
Purpose:
Parameters:
CLSF
The CLSF parameter specifies the class file, ZIP file, or JAR file name from
which to delete the associated Java program on AS/400. One or more
directory names may qualify the class file name.
For class-file-name, specify the name of the class file or a pattern to
identify file or files to be used. A pattern may be specified in the last part
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 85
of the name. An asterisk matches any number of characters, and a question
mark matches a single character. Enclose the name in apostrophes if it is
qualified or contains a pattern. An example of a qualified class name is:
'/directory1/directory2/myclassname.class'
SUBTREE
The SUBTREE parameter specifies whether or not subdirectories are
processed when looking for files that match the CLSF keyword.
*NONE
Only the files that match the object name pattern are processed. No
subtrees are processed. If the directory has subdirectories, neither
the subdirectories nor the objects on the subdirectories are
processed.
*ALL The entire subtree of the path that is specified in CLSF is processed
to create Java programs for files that match the name that was
specified on the CLSF parameter.
See Example: Delete Java Program (DLTJVAPGM) command for an example that
uses the DLTJVAPGM command.
Note: The DLTJVAPGM command does not delete the class file or ZIP file.
DLTJVAPGM CLSF(’/projectA/team2/myJavaClassFileName.class’)
See the Delete Java Program (DLTJVAPGM) command for syntax diagram and
parameter details.
Purpose:
The Dump Java Virtual Machine (DMPJVM) command dumps information about
the Java virtual machine for a specified job. The dump includes formatted
information about the classpath, garbage collection, and threads that are associated
with the Java virtual machine.
Syntax:
Restrictions:
v The DMPJVM command uses the Start Service Job (STRSRVJOB) command and
Start Debug (STRDBG) command. The user of this command must be authorized
to the STRSRVJOB command and STRDBG command.
v The DMPJVM command ships with public *EXECUTE authority, and the
QPGMR, QSYSOPR, QSRV, and QSRVBAS user profiles have private authorities
to use the DMPJVM command.
v The DMPJVM command must run under a user profile, which is the same as the
job user identity of the Java virtual machine job, or which has use (*USE)
authority to the job user identity of the Java virtual machine job.
v The DMPJVM command is not allowed if the remote service operation for
another job has started, and that job is not the same job that was specified on
this command.
v The DMPJVM command is not allowed if the Java virtual machine job is held,
suspended, or ending.
Optional parameters:
JOB The JOB parameter specifies the name of the job where the Java virtual
machine is running. If no job number is given, all of the jobs that are
currently in the system are searched for the simple job name. The job name
entered must be a job in which a Java virtual machine is currently running.
*SRVJOB
Information about the Java virtual machine in the job that is
currently being serviced is dumped. If no job is currently being
serviced, a job identifier is required.
A job identifier is a qualified name with up to three elements. For
example:
v job-name
v user-name/job-name
v job-number/user-name/job-name
job-name
Specifies the name of the Java virtual machine job.
user-name
Specifies the name of user of the Java virtual machine job.
job-name
Specifies the number of the Java virtual machine job.
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 87
STACKFRAME
The STACKFRAME parameter specifies the maximum number of stack
frames for each thread to process. This value must be greater than zero,
and cannot be greater than 100. If there are more than the specified
number of frames on a thread stack, the more recent frames on the stack
are processed and ’...’ indicates that not all of the stack frames were
processed.
10 Each thread processes a maximum of ten stack frames.
*ALL Each thread processes all stack frames. If a thread has more than
100 stack frames, only the first 100 frames are processed.
number
The maximum number (1-100) of stack frames that the thread
processes.
DUPJOBOPT
Specifies the action to be taken when the DMPJVM command finds
duplicate jobs.
*SELECT
When the DMPJVM command finds duplicate jobs during an
interactive session, the selection display is shown. Otherwise, an
escape message is issued.
*MSG When the DMPJVM command finds duplicate jobs, an escape
message is issued.
See Example: Dump Java Virtual Machine (DMPJVM) command for an example
that uses the DMPJVM command.
The DMPJVM command dumps the information for the Java virtual machine that
is running in the job that is named 099246/FRED/QJVACMDSRV.
Example output:
JAVA VIRTUAL MACHINE INFORMATION: 099246/FRED/QJVACMDSRV
......................................................................
. Classpath
......................................................................
/QIBM/ProdData/Java400/jdk117/lib/jdkptf117.zip:/QIBM/ProdData/Java400/jdk1
17/lib/classes.zip:/QIBM/ProdData/Java400/ext/IBMmisc.jar:/QIBM/ProdData/Ja
va400/ext/db2_classes.jar:/QIBM/ProdData/Java400/ext/jssl.jar:/QIBM/ProdDat
a/Java400/ext/ibmjssl.jar:/QIBM/ProdData/Java400/:/home/fred
......................................................................
. Garbage collection
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 89
DSPJVAPGM Command
(1)
>>-DSPJVAPGM—-CLSF(—'class-file-name'—)———————————>
>——-+—————————————+——————————————-><
| .-*———. |
'-OUTPUT(—+-*PRINT-+—-)—'
Note:
Purpose:
Parameters:
CLSF The CLSF parameter specifies the class file, ZIP file, or JAR file name from
which to display the associated Java program on AS/400. One or more
directory names may qualify the class file name.
For class-file-name, specify the name of the class file, ZIP file, or JAR file.
An example of a qualified class name is:
'/directory1/directory2/myclassname.class'
OUTPUT
The OUTPUT parameter specifies where the output is to be sent.
* Display shows the output that was requested by an interactive job.
Output that was requested by a batch job prints with the spooled
output of the job.
*PRINT
The output prints with the spooled output of the job.
Display example:
This display example shows you what Display Java Program (DSPJVAPGM)
output looks like for a ZIP file.
+————————————————————————————————————————+
Display Java Program Information
File name . . . . . . . . . . . . . . . : /user/classes.zip1
Owner . . . . . . . . . . . . . . . . . : USER2
Java program creation information:
File change date/time . . . . . . . . . . . . . : 07/18/98 09:03:373
Java program creation date/time . . . . . . . . : 07/18/98 14:03:384
Java programs . . . . . . . . . . . . . . . . . : 15
Classes with current Java programs . . . . . . : 16
Classes without current Java programs . . . . . : 07
Optimization . . . . . . . . . . . . . . . . . : *INTERPRET8
Enable performance collection . . . . . . . . . : *NONE9
Use adopted authority . . . . . . . . . . . . . : *NO10
User profile . . . . . . . . . . . . . . . . . : *USER11
Licensed Internal Code options . . . . . . . . : ErrorReporting=012
Java program statistics:
Java program size . . . . . . . . . . . . . . . : 270745613
Release program created for . . . . . . . . . . : V4R5M014
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 91
and display program variables. You can display, but not change
variables while debugging. The values that are presented may not be
the current value of the variable.
40 The Java program contains a compiled version of the class file
bytecodes and has more compiler optimization than optimization level
30. In addition, it includes optimization that disables call and
instruction tracing.
Note: If your Java program fails to optimize or throws an exception at
optimization level 40, use optimization level 30.
*INTERPRET
The Java program is not optimized. When the program starts, it
interprets the class file bytecodes. You can display and change
variables while debugging.
9. Enable performance collection: This is the level of performance data
collection that is allowed for this Java program. These values can be returned:
*NONE
No performance collection is enabled for this Java program.
*ENTRYEXIT
This gives the entry and exit information on all of the procedures of
the Java program, including those that were leaf procedures. This also
includes the PEP routine. *ENTRYEXIT is useful in capturing
information on all procedures.
*FULL This gives the entry and exit information on all of the procedures of
the Java program, including those that were leaf procedures. Also,
precall and postcall hooks around other calls to other procedures.
*FULL is useful in capturing information on all procedures.
10. Use adopted authority: Indicates if the Java programs use adopted authority
from previous call levels in the stack.
11. User profile: Indicates if the authority checking that was done while this
program is running should include only the user who is running the program
(*USER), or both the user who is running the program and the program owner
(*OWNER).
12. Licensed Internal Code options: The selected licensed internal code (LIC)
compile-time options that are used when the Java program was created.
13. Java program size: The size, in bytes, of the Java programs that are attached
to the file.
14. Release program create for: The release of the operating system for which
the object was created.
See Example: Display Java Program (DSPJVAPGM) command for an example that
uses the DSPJVAPGM command.
See the Display Java Program (DSPJVAPGM) command for syntax diagram and
parameter details.
Class files reside in the integrated file system. Operations Navigator allows you to
see these class files in the right pane. Right-click the class file that you want to use.
This brings up a context menu.
Selecting the New Java program from the context menu starts the Java transformer,
which creates an AS/400 Java program that is associated with your class file. A
dialog box allows you to specify details on how to create the program. You can
create the program for either Java transformation or Java interpretation.
Note:If you select transformation, the bytecodes in your class file transform into
RISC instructions that result in better performance than if you used interpretation.
Selecting Change Java program from the context menu changes attributes of Java
programs that are attached to Java class files, ZIP files, or JAR files.
Selecting Run Java program from the context menu runs your class file on AS/400.
A dialog appears to allow you to specify details on how to run the program. If you
have already selected New Java program, the AS/400 Java program that is
associated with your class file is used when running the program. If an AS/400
Java program is not already associated with your class file, then the AS/400 Java
program is created before the program runs.
Selecting Delete Java program from the context menu deletes the AS/400 Java
program that is associated with your class file.
See the online help information for the parameters and options of the New Java
program, Change Java program, Run Java program, and Delete Java program
Operations Navigator commands.
Chapter 4. Commands and tools for the AS/400 Developer Kit for Java 93
94 AS/400 Developer Kit for Java
Chapter 5. Using Java with other programming languages
With Java, you have multiple ways to call code that was written in languages other
than Java.
One of the ways you can call code written in another language is to implement
selected Java methods as ’native methods.’ Native methods are procedures, written
in another language, that provide the actual implementation of a Java method.
Native methods can access the Java virtual machine using the Java Native Interface
(JNI). These native methods run under the Java thread, which is a kernel thread, so
they must be thread safe. A function is thread safe if you can start it
simultaneously in multiple threads within the same process. A function is thread
safe if and only if all the functions it calls are thread safe also.
Native methods are a “bridge” to access system functions that are not directly
supported in Java, or to interface to existing user code. Use caution when using
native methods, because the code that is being called may not be thread safe. See
using the Java Native Interface for native methods for more information about JNI
and native methods.
java.lang.Runtime.exec():
Interprocess communication:
One option is to use sockets for interprocess communication between the parent
and child processes.
You can also use stream files for communication between programs. Or see
interprocess communication examples for an overview of your options when
communicating with programs that are running in another process.
To call Java from other languages, see calling Java from other languages.
You can also use the AS/400 Toolbox for Java to call existing programs and
commands on AS/400. Data queues and AS/400 messages are usually used for
interprocess communication with the AS/400 Toolbox for Java.
Note: By using Runtime.exec(), AS/400 Toolbox for Java, or JNI you may
compromise the portability of the Java program. You should avoid using these
methods in a “pure” Java environment.
Using the Java Invocation API, which is also a part of the Java Native Interface
(JNI) specification, allows a non-Java application to use the Java virtual machine. It
also allows the use of Java code as an extension of the application.
6. Write the native method code. See Java native methods and threads
considerations for details about the languages and functions that are used for
native methods.
a. Include the header file that was created in the previous steps.
b. Match the prototypes in the header file exactly.
c. Convert strings to American National Standard Code for Information
Interchange (ASCII) if the strings are to pass to the Java virtual machine.
For more information, see Java character encodings.
7. If your native method must interact with the Java virtual machine, use the
functions that are provided with JNI.
8. Compile your C source code, using the CRTCMOD, into a module (*MOD)
object.
9. Bind one or more module objects into a service program (*SRVPGM) by using
the Create Service Program (CRTSRVPGM) command. The name of this service
program must match the name that you supplied in your Java code that is in
the System.load() or System.loadLibrary() function calls.
Where /QSYS.LIB/MYLIB.LIB is the library that you wish to load using the
’System.loadLibrary()’ call, and myclass is the name of your Java application.
11.
The patches syntax for System.load(String patches) can be any of these:
v “path” (integrated file system filename that specifies the library that the
service program provides), which is a symbolic link to a *SRVPGM, such as
“/qsys.lib/mylib.lib/myNMsp.srvpgm”
v /qsys.lib/sysNMsp.srvpgm
v /qsys.lib/mylib.lib/myNMsp.srvpgm
Note: If the “pathname” is used as a string literal, then you must enclose it in
quotation marks. For example,
System.load(“/qsys.lib/mylib.lib/myNMsp.srvpgm”).
12.
The “libya” syntax for System.loadLibrary(String libya) is mysp. The system
finds mysp by using *LIBL. For example, loadLibrary(“myNMsp”) is
See Examples: Using the Java Native Interface for native methods for an example
of how to use the JNI for native methods.
To better use Java with native methods you need to understand these concepts:
v A Java thread, whether created by Java or an attached native thread, has all
floating point exceptions disabled. If the thread runs a native method that
reenables floating point exceptions, Java does not turn them off a second time. If
the user application does not disable them before returning to run Java code,
then the Java code may not behave correctly if a floating point exception occurs.
When a native thread detaches from the Java virtual machine, its floating point
exception mask is restored to the value that was in effect when it was attached.
v When a native thread attaches to the Java virtual machine, the Java virtual
machine changes the threads priority, if necessary, to conform to the one to ten
priority schemes that Java defines. When the thread detaches, the priority is
restored. After attaching, the thread can change the thread priority by using a
native method interface (for example, a POSIX API). Java does not change the
thread priority on transitions back to the Java virtual machine.
v The Invocation API component of the Java Native Interface (JNI) permits a user
to embed a Java virtual machine within their application. If an application
creates a Java virtual machine and the Java virtual machine ends abnormally, the
MCH74A5 “Java Virtual Machine Terminated” AS/400 exception is signalled to
the initial thread of the process if that thread was attached to the Java virtual
machine when the Java virtual machine ended. The Java virtual machine could
end abnormally for any of these reasons:
– The user calls the java.lang.System.exit() method.
– A thread that the Java virtual machine requires ends.
– An internal error occurs in the Java virtual machine.
This behavior differs from most other Java platforms. On most other platforms,
the process that automatically creates the Java virtual machine ends abruptly as
soon as the Java virtual machine ends. If the application monitors and handles a
signalled MCH74A5 exception, it may continue to run. Otherwise, the process
ends when the exception goes unhandled. By adding the code that deals with
the AS/400-specific MCH74A5 exception you can make the application less
portable to other platforms.
Because native methods always run in a multithreaded process, the code that they
contain must be thread safe. This places these restrictions on the languages and
functions that are used for native methods:
All JNI functions expect their string parameters to be encoded in UTF-8. For details
on UTF-8, you can refer to the JNI Specification, but in most cases it is enough to
observe that 7-bit American National Standard Code for Information Interchange
(ASCII) characters are equivalent to their UTF-8 representation. 7-bit ASCII
characters are actually 8-bit characters but their first bit is always 0. So, most ASCII
C strings are actually already in UTF-8.
For example, to find the class named “java/lang/String” the code looks like this:
#pragma convert(819)
myClass = (*env)->FindClass(env,“java/lang/String”);
#pragma convert(0)
The first pragma, with the number 819, informs the compiler to store all
subsequent double-quoted strings (literal strings) in ASCII. The second pragma,
with the number 0, tells the compiler to revert to the default code page of the
compiler for double-quoted strings, which is usually the EBCDIC code page 37. So,
by bracketing this call with these pragmas, we satisfy the JNI requirement that
string parameters are encoded in UTF-8.
Caution: Be careful with text substitutions. For example, if your code looks like
this:
#pragma convert(819)
#define MyString “java/lang/String”
#pragma convert(0)
myClass = (*env)->FindClass(env,MyString);
Then, the resulting string is EBCDIC, because the value of MyString is substituted
into the FindClass call during compilation. At the time of this substitution, the
pragma, number 819, is not in effect. Thus, literal strings are not stored in ASCII.
The system API that provides for code page conversion function is iconv(). To use
iconv(), follow these steps:
1. Create a conversion descriptor with QtqIconvOpen().
2. Call iconv() to use the descriptor to convert to a string.
3. Close the descriptor by using iconv_close.
In Example 3 of the using the Java Native Interface for native methods examples,
the routine creates, uses, and then destroys the iconv conversion descriptor within
the routine. This scheme avoids the problems with multithreaded use of an iconv_t
descriptor, but for performance sensitive code it is better to create a conversion
descriptor in static storage, and moderate multiple access to it using a mutual
exclusion (mutex) or other synchronization facility.
These reasons, although they are not new with the JNI, cause some unique,
AS/400-specific differences in the C code that you write. You must remember that
if you are writing to stdout or stderr or reading from stdin, your data is probably
encoded in EBCDIC form.
In C code, you can easily convert most literal strings, those that contain 7-bit
characters only, into the UTF-8 form that is required by the JNI. To do this, bracket
the literal strings with code-page conversion pragmas. However, because you may
write information directly to stdout or stderr from your C code, you might allow
some literals to remain in EBCDIC.
Note: The #pragma convert(0) statements convert character data to EBCDIC. The
#pragma convert(819) statements convert character data to American National
Standard Code for Information Interchange (ASCII). These statements convert
character data in the C program at compile time.
Using java.lang.Runtime.exec()
The java.lang.Runtime.exec() method calls programs or commands from within a
Java program. The actual processing that occurs depends on exactly what
information is passed to the exec() method. In all cases, the Runtime.exec() method
creates another thread-enabled batch immediate (BCI) job. The BCI job processes
the command string that is passed in on the Runtime.exec() method.
To use the java.lang.Runtime.exec() method, you must install the Qshell Interpreter
on your AS/400. For more information about the Qshell Interpreter, see Qshell
Interpreter.
If the command being processed is a Qshell utility, it runs in the second BCI job,
and the third BCI job is not created. If the command being processed is a CL
command, the second BCI job is started to run the Qshell, and the third BCI job is
started to run the CL command. A Qshell utility is a built-in utility that QSH can
run directly. An example of a Qshell utility is the javac command, which compiles
Java programs. The processing in the second (or third) BCI job runs concurrently
with the Java virtual machine. Any exit or shutdown processing in those jobs does
not affect the original Java virtual machine.
When calling an AS/400 command or program, you must ensure that any
parameters being passed to the called program are in the code page that is
expected by that program.
import java.io.*;
public class CallHelloPgm
{
public static void main(String args[])
{
Process theProcess = null;
BufferedReader inStream = null;
System.out.println(“CallHelloPgm.main() invoked”);
// call the Hello class
try
{
theProcess = Runtime.getRuntime().exec(“java com.ibm.as400.system.Hello”);
}
catch(IOException e)
{
System.err.println(“Error on exec() method”);
e.printStackTrace();
}
// read from the called program's standard output stream
try
{
inStream = new BufferedReader(
new InputStreamReader( theProcess.getInputStream() ));
System.out.println(inStream.readLine());
}
catch(IOException e)
{
System.err.println(“Error on inStream.readLine()”);
e.printStackTrace();
}
} // end method
} // end class
Note: The JAVSAMPLIB is not created as part of the AS/400 Developer Kit
licensed program (LP) number 5769-JV1 installation process. You must explicitly
create the library.
One option is to use sockets for interprocess communication. One program can act
as the server program, that listens on a socket connection for input from the client
program. The client program connects to the server with a socket. Once the socket
connection is established, either program can send or receive information.
A third option is to use the AS/400 Toolbox for Java which provides data queues
and AS/400 message objects.
For an example that uses sockets, see Example: Using sockets for interprocess
communication.
The Java program should be started using this command, java TalkToC xxxxx
nnnn on the Qshell Interpreter command line or on another Java platform. Or, enter
JAVA TALKTOC PARM(xxxxx nnnn) on the AS/400 command line to start the Java
program. xxxxx is the domain name or Internet Protocol (IP) address of the system
on which the C program is running. nnnn is the port number of the socket that the
C program is using. You should also use this port number as the first parameter on
the call to the C program.
SockServ.C starts by passing in a parameter for the port number. For example, CALL
SockServ ’2001’.
For an example that uses input and output streams, see Example: Using input and
output streams for interprocess communication.
Note: The JAVSAMPLIB is not created as part of the AS/400 Developer Kit
licensed program (LP) number 5769-JV1 installation process. You must explicitly
create it.
For more information, see Using input and output streams for interprocess
communication.
Note: Any of these calls cause another process to be created in which the Java
virtual machine is run. To communicate between the processes, you must use some
form of interprocess communication. Some methods of interprocess communication
are sockets, data queues, and stream files. If data is passing between the programs,
it is necessary to ensure that the programs convert that data properly.
For examples of how to call the Java Hello program in C or RPG, see Example:
Calling Java from C or Example: Calling Java from RPG, respectively.
You can also use the Java Invocation API specification, which allows a non-Java
application, such as C, to use the Java virtual machine.
The application controls the Java virtual machine. The application can create the
Java virtual machine, call Java methods (similar to the way in which an application
calls subroutines), and destroy the Java virtual machine. Once you create the Java
virtual machine, it remains ready to run within the process until the application
explicitly destroys it. While being destroyed, the Java virtual machine performs
clean-up, such as running finalizers, ending Java virtual machine threads, and
releasing Java virtual machine resources.
With a Java virtual machine that is ready to run, an application written in C can
call into the Java virtual machine to perform any function. It also can return from
the Java virtual machine to the C application, call into the Java virtual machine
again, and so on. The Java virtual machine is created once and does not have to be
re-created before calling into the Java virtual machine to run a little or a lot of Java
code.
When using the Invocation API to run Java programs, the destination for STDOUT
and STDERR is controlled by the use of an environment variable called
QIBM_USE_DESCRIPTOR_STDIO. If this environment variable is set to Y or I (for
example, QIBM_USE_DESCRIPTOR_STDIO=Y), the Java virtual machine uses file
descriptors for STDIN (fd 0), STDOUT (fd 1), and STDERR (fd 2). In this case, the
program must set these file descriptors to valid values by opening them as the first
three files or pipes in this job. The first file opened in the job is given fd of 0, the
second fd of 1, and third is fd of 2. For jobs initiated with the spawn API, these
descriptors can be preassigned using a file descriptor map (see documentation on
Spawn API). If the environment variable QIBM_USE_DESCRIPTOR_STDIO is not
set or is set to any other value, file descriptors are not used for STDIN, STDOUT,
or STDERR. Instead, STDOUT and STDERR are routed to a spooled file that is
owned by the current job, and use of STDIN results in an IO exception.
For an example that uses the Invocation API, see Example: Java Invocation API.
See Invocation API functions for details about the Invocation API functions that are
supported by the AS/400 Developer Kit for Java.
p_vm is the address of a JavaVM pointer for the newly created Java virtual
machine. Several other JNI Invocation APIs use p_vm to identify the Java virtual
machine. p_env is the address of a JNI Environment pointer for the newly
created Java virtual machine. It points to a table of JNI functions that start those
functions. vm_args is a structure that contains Java virtual machine initialization
parameters. When using JDK 1.1.x, you can obtain a structure that contains
default values by calling JNI_GetDefaultJavaVMInitArgs. For details on how to
If you start a Run Java (RUNJVA) command or JAVA command and specify a
property that has an equivalent command parameter, then the command
Note:With multiple Java virtual machines within one process, all Java virtual
machines share the same process static storage that is allocated for any native
methods. Java virtual machine internal implementation already partitions data
on a per-Java virtual machine basis, but you must consider that with native
method applications Java virtual machines share process static storage. For other
considerations, see support for multiple Java virtual machines.
v DestroyJavaVM
Destroys the Java virtual machine.
Signature:
jint DestroyJavaVM(JavaVM *vm)
When the Java virtual machine is created, vm is the JavaVM pointer that is
returned.
v AttachCurrentThread
Attaches a thread to a Java virtual machine, so it can use Java virtual machine
services.
Signature for Java Development Kit (JDK) 1.1.x:
jint AttachCurrentThread(JavaVM *vm,
JNIEnv **p_env,
void *thr_args);
The JavaVM pointer, vm, identifies the Java virtual machine to which the thread
is being attached. p_env is the pointer to the location where the JNI Interface
pointer of the current thread is placed. thr_args contains VM specific thread
attachment arguments.
v DetachCurrentThread
Signature:
jint DetachCurrentThread(JavaVM *vm);
vm identifies the Java virtual machine from which the thread is being detached.
For a complete description of the Invocation API functions, refer to the Java Native
Interface Specification by Sun Microsystems, Inc., or The Source for Java
Technology java.sun.com.
If you want to create multiple Java virtual machines for use within a single job or
process, you should carefully consider the following:
If you use the ILE/C exit() or abort() routines in any thread of a multithreaded
job you will immediately bring down the entire job, including all Java virtual
machines.
Note: The C runtime exit() routine used below is not recommended unless you
know that your program is the only thread in the process. When called from a
process that is capable of supporting multiple threads, exit() immediately ends all
threads in a process.
With the AS/400 Developer Kit for Java JDBC driver your Java programs can
access AS/400 database files, access JDBC database functions with embedded
Structured Query Language (SQL) for Java, and run SQL statements and process
results. JDBC is a standard part of Java and is included on AS/400. JDBC is a
Java API for running structured query language (SQL) statements. It allows the
user to issue SQL statements and process the results.
You can access AS/400 databases through two JDBC drivers: AS/400 Developer Kit
for Java driver or AS/400 Toolbox for Java JDBC driver. For specific information
about the AS/400 Toolbox for Java JDBC driver, see AS/400 Toolbox for Java.
For more information about JDBC, see the JDBC by Sun Microsystems, Inc.
documentation.
For more information about AS/400 Native JDBC Driver, see AS/400 Developer
Kit for Java JDBC Web Page.
Registering the AS/400 Developer Kit for Java JDBC driver before
using JDBC
You must register the AS/400 Developer Kit for Java JDBC driver with the
DriverManager before using JDBC to access data in an AS/400 database file.
You can either use a Java system property or have the Java program register the
drivers.
v Registration that uses a system property.
Each Java virtual machine has its own method of setting system properties. For
example, the java command in Qshell uses the -d option to set system
properties.
To set the driver using system properties, specify this command from the Qshell
Interpreter:
java -djdbc.drivers=com.ibm.db2.jdbc.app.DB2Driver MySQL
To set the driver using system properties, specify this from the CL command
line:
JAVA CLASS(MySQL)
PROP((jdbc.drivers com.ibm.db2.jdbc.app.DB2Driver))
The systemName contains an entry from the relational database directory. Enter the
Work with Relational Database Directory Entries (WRKRDBDIRE) command to
display or add the system name. Then, specify *LOCAL for the remote location in
the WRKRDBDIRE command. Typically, the name that is chosen is the same name
as the system name of the AS/400 that contains the database.
See Examples: Connecting to an AS/400 database using the AS/400 Developer Kit
for Java JDBC driver for an example of how to connect to an AS/400 database.
The Java program can specify a set of JDBC properties either by using the
java.util.Properties interface or by specifying the properties as part of the URL.
This example specifies properties by using the Properties interface.
Chapter 6. Accessing your AS/400 database with the AS/400 Developer Kit for Java JDBC driver 123
c.close();
For more information, see connecting to an AS/400 database using the AS/400
Developer Kit for Java JDBC driver.
Chapter 6. Accessing your AS/400 database with the AS/400 Developer Kit for Java JDBC driver 125
“select * from MYLIBRARY.MYTABLE”;
// Run an SQL query on the table.
ResultSet rs = s.executeQuery(myQuery);
System.out.println(
“Query result: \n”);
ResultSetMetaData rsmd = rs.getMetaData();
System.out.println(rsmd.getColumnName(1) + “” + rsmd.getColumnName(2));
System.out.println(“————”);
while (rs.next()) {
String value1 = rs.getString(1);
int value2 = rs.getInt(2);
System.out.println(value1 + “” + value2);
}
// Close the Statement.
s.close();
// Close the connection.
c.close();
}
}
For more information, see AS/400 Developer Kit for Java JDBC driver.
See Example: Statement interface for AS/400 Developer Kit for Java for an example
of a Statement object.
For more information, see Statement interface for AS/400 Developer Kit for Java.
See Example: PreparedStatement interface for AS/400 Developer Kit for Java for an
example of the Prepared Statement interface.
For more information, see PreparedStatement interface for AS/400 Developer Kit
for Java.
Chapter 6. Accessing your AS/400 database with the AS/400 Developer Kit for Java JDBC driver 127
CallableStatement interface for AS/400 Developer Kit for Java
A CallableStatement object runs structured query language (SQL) stored
procedures. The stored procedure that is being called must already be stored in the
database. CallableStatement does not contain the stored procedure, only the call to
the stored procedure.
A stored procedure can return one or more ResultSet objects, and can use IN
parameters, OUT parameters, and INOUT parameters.
See Example: CallableStatement interface for AS/400 Developer Kit for Java for an
example of how to use the CallableStatement interface.
For more information, see CallableStatement interface for AS/400 Developer Kit for
Java.
See Example: ResultSet interface for AS/400 Developer Kit for Java for an example
of how to use the ResultSet interface.
For more information, see ResultSet interface for AS/400 Developer Kit for Java.
See Example: DatabaseMetaData interface for AS/400 Developer Kit for Java for an
example of how to use the DatabaseMetaData interface.
Chapter 6. Accessing your AS/400 database with the AS/400 Developer Kit for Java JDBC driver 129
Example: DatabaseMetaData interface for AS/400 Developer
Kit for Java
This example shows how to return a list of tables.
For more information, see DatabaseMetaData interface for AS/400 Developer Kit
for Java.
NOTE: Only use the Blob interface if you are also using Java 2 to develop your
application.
With the Blob class, the lob threshold property can be used. This property specifies
the maximum large object (LOB) size (in kilobytes) that can be retrieved as part of
a result set. LOBs that are larger than this threshold are retrieved in pieces using
extra communication to the server. Larger LOB thresholds reduce the frequency of
communication to the server, but they download more LOB data, even if it is not
used. Smaller lob thresholds may increase frequency of communication to the
server, but they only download LOB data as it is needed.
NOTE: Use the Clob interface only if you are using Java 2 to develop your
application.
With the Clob class, the lob threshold property can be used. This property specifies
the maximum large object (LOB) size (in kilobytes) that can be retrieved as part of
a result set. LOBs that are larger than this threshold are retrieved in pieces using
extra communication to the server. Larger LOB thresholds reduce the frequency of
communication to the server, but they download more LOB data, even if it is not
used. Smaller lob thresholds may increase frequency of communication to the
server, but they only download LOB data as it is needed.
Chapter 6. Accessing your AS/400 database with the AS/400 Developer Kit for Java JDBC driver 131
132 AS/400 Developer Kit for Java
Chapter 7. Accessing databases using AS/400 Developer Kit
for Java DB2 SQLJ support
DB2 Structured Query Language for Java (SQLJ) support is based on the SQLJ
ANSI standard. The DB2 SQLJ support is contained in the AS/400 Developer Kit
for Java. DB2 SQLJ support allows you to create, build, and run embedded SQL for
Java applications.
The SQLJ support provided by the AS/400 Developer Kit for Java includes the
SQLJ run-time classes, and is available in
/QIBM/ProdData/Java400/ext/runtime.zip. For more information on the SQLJ
run-time classes, refer to the Runtime API documentation supplied in the
SQLJ tools
The following tools are also included in the SQLJ support provided by the AS/400
Developer Kit for Java.
Note:These tools must be run in the Qshell Interpreter:
v The SQLJ translator, sqlj, replaces embedded SQL statements in the SQLJ
program with Java source statements and generates a serialized profile that
contains information about the SQLJ operations that are found in the SQLJ
program.
v The DB2 SQLJ Profile Customizer, db2profc, precompiles the SQL statements
stored in the generated profile and generates a package in the DB2 database.
v The DB2 SQLJ Profile Printer, db2profp, prints the contents of a DB2 customized
profile in plain text.
v The SQLJ profile auditor installer, profdb, installs and uninstalls debugging
class-auditors into an existing set of binary profiles.
v The SQLJ profile conversion tool, profconv, converts a serialized profile instance
to Java class format.
Before you create any SQLJ clauses in your Java application, import the following
packages:
v import java.sql.*;
v import sqlj.runtime.*;
v import sqlj.runtime.ref.*;
The simplest SQLJ clauses are executable clauses and consist of the token #sql
followed by an SQL statement enclosed in braces. For example, the following SQLJ
clause may appear wherever a Java statement may legally appear:
The example above will delete all the rows in the table named TAB.
Note: For information on compiling and running SQLJ applications, see Compiling
and running SQLJ Programs.
In an SQLJ executable clause, the tokens that appear inside the braces are either
SQL tokens or host variables. All host variables are distinguished by the colon (:)
character. SQL tokens never occur outside the braces of an SQLJ executable clause.
For example, the following Java method inserts its arguments into an SQL table:
public void insertIntoTAB1 (int x, String y, float z) throws SQLException
{
#sql { INSERT INTO TAB1 VALUES (:x, :y, :z) };
}
The method body consists of an SQLJ executable clause containing the host
variables x, y, and z. For more information on host variables, see Host variables in
SQLJ.
In general, SQL tokens are case insensitive (except for identifiers delimited by
double quotation marks), and can be written in upper, lower, or mixed case. Java
tokens, however, are case sensitive. For clarity in examples, case insensitive SQL
tokens are uppercase, and Java tokens are lowercase or mixed case. Throughout
this chapter, the lowercase null is used to represent the Java “null” value, and the
uppercase NULL is used to represent the SQL “null” value.
Note: The SQLJ translator automatically compiles the translated Java source
code into a class file unless you explicitly turn off the compile option with the
-compile=false clause.
2. Use the SQLJ Profile Customizer tool, db2profc, to install DB2 SQLJ
Customizers on generated profiles and create the DB2 packages on the local
system.
For example, type in the command:
db2profc MyClass_SJProfile0.ser
Where MyClass_SJProfile0.ser is the name of the profile on which the DB2
SQLJ Customizer will run.
Chapter 7. Accessing databases using AS/400 Developer Kit for Java DB2 SQLJ support 135
For example, type in:
java MyClass
Where MyClass is the name of your Java class file.
The following query contains the host variable, :x. This host variable is the Java
variable, field, or parameter x that is visible in the scope containing the query.
To generate profiles from your SQLJ source code, run the SQLJ translator, sqlj, on
your .sqlj file.
Chapter 7. Accessing databases using AS/400 Developer Kit for Java DB2 SQLJ support 137
cursor1.close(); // 9
// retrieve number of employee from the database
#sql { SELECT count(*) into :count1 FROM employee }; // 5
if (1 == count1)
System.out.println (“There is 1 row in employee table”);
else
System.out.println (“There are ” + count1
+ “ rows in employee table”);
// update the database
System.out.println(“Update the database.”);
#sql { UPDATE employee SET firstnme = 'SHILI' WHERE empno = '000010' };
// retrieve the updated data from the database
System.out.println(“Retrieve the updated data from the database.”);
str1 = “000010”;
#sql cursor2 = {SELECT firstnme FROM employee WHERE empno = :str1}; // 6
// display the result set
// cursor2.next() returns false when there are no more rows
System.out.println(“Received results:”);
while (true)
{
#sql { FETCH :cursor2 INTO :str2 }; // 7
if (cursor2.endFetch()) break; // 8
System.out.print (“ empno= ” + str1);
System.out.print (“ firstname= ” + str2);
System.out.println(“”);
}
cursor2.close(); // 9
// rollback the update
System.out.println(“Rollback the update.”);
#sql { ROLLBACK work };
System.out.println(“Rollback done.”);
}
catch( Exception e )
{
e.printStackTrace();
}
}
}
1. Declare iterators. This section declares two types of iterators:
App_Cursor1
Declares column data types and names, and returns the values of the
columns according to column name (Named binding to columns).
App_Cursor2
Declares column data types, and returns the values of the columns by
column position (Positional binding to columns).
2. Initialize the iterator. The iterator object cursor1 is initialized using the result
of a query. The query stores the result in cursor1.
3. Advance the iterator to the next row. The cursor1.next() method returns a
Boolean false if there are no more rows to retrieve.
4. Move the data. The named accessor method empno() returns the value of the
column named empno on the current row. The named accessor method
firstnme() returns the value of the column named firstnme on the current row.
5. SELECT data into a host variable. The SELECT statement passes the number
of rows in the table into the host variable count1.
6. Initialize the iterator. The iterator object cursor2 is initialized using the result
of a query. The query stores the result in cursor2.
7. Retrieve the data. The FETCH statement returns the current value of the first
column declared in the ByPos cursor from the result table into the host variable
str2.
For more information on sqlj command line options, refer to the SQLJ User’s Guide
and Reference supplied in the Implementation from www.sqlj.org .
Where SQLJ profile name is the name of the profile to be printed and options is
the list of options you want.
The options available for db2profp are:
-url=<JDBC URL>
Chapter 7. Accessing databases using AS/400 Developer Kit for Java DB2 SQLJ support 139
-user=<user name>
-password=<password>
-package=<library name/ package name>
-commitctrl=<commitment control>
-datefmt=<date format>
-datesep=<date separator>
-timefmt=<time format>
-timesep=<time separator>
-decimalpt=<decimal point>
-stmtCCSID=<coded character set identifier for the SQL statement
text>
-sorttbl=<library name/sort sequence table name>
-langID=<language identifier>
Value Definition
C *CHG. Dirty reads, non-repeatable reads and
phantom reads are possible.
S *CS. Dirty reads are not possible but
non-repeatable reads and phantom reads are
possible.
A *ALL. Dirty reads and non-repeatable reads
are not possible but phantom reads are
possible.
N *NONE. Dirty reads, non-repeatable reads,
and phantom reads are not possible. This is
the default.
-datefmt=<date format>
Where date format is the type of date formatting you want. Date format
can have any one of the following values:
Value Definition
USA IBM USA standard (mm.dd.yyyy,hh:mm
a.m., hh:mm p.m.)
ISO International Standards Organization
(yyyy-mm-dd, hh.mm.ss) This is the default.
EUR IBM European Standard (dd.mm.yyyy,
hh.mm.ss)
JIS Japanese Industrial Standard Christian Era
(yyyy-mm-dd, hh:mm:ss)
MDY Month/Day/Year (mm/d/yy)
DMY Day/Month/Year (dd/mm/yy)
YMD Year/Month/Day (yy/mm/dd)
JUL Julian (yy/ddd)
Date format is used when accessing date result columns. All output date
fields are returned in the specified format. For input date strings, the
specified value is used to determine whether the date is specified ina valid
format. The default value is ISO.
-datesep=<date separator>
Where date separator is the type of separator you want to use. Date
separator is used when accessing date result columns. Date separator can
be any of the following values:
Value Definition
/ A slash is used.
. A period is used.
, A comma is used.
- A dash is used. This is the default.
blank A space is used.
-timefmt=<time format>
Where time format is the format you want to use to display time fields.
Time format is used when accessing time result columns. For input time
strings, the specified value is used to determine whether the time is
specified in a valid format. Time format can be any one of the following
values:
Chapter 7. Accessing databases using AS/400 Developer Kit for Java DB2 SQLJ support 141
Value Definition
USA IBM USA standard (mm.dd.yyyy,hh:mm
a.m., hh:mm p.m.)
ISO International Standards Organization
(yyyy-mm-dd, hh.mm.ss) This is the default.
EUR IBM European Standard (dd.mm.yyyy,
hh.mm.ss)
JIS Japanese Industrial Standard Christian Era
(yyyy-mm-dd, hh:mm:ss)
HMS Hour/Minute/Second (hh:mm:ss)
-timesep=<time separator>
Where time separator is the character you wish to use to access your time
result columns. Time separator can be any one of the following values:
Value Definition
: A colon is used.
. A period is used. This is the default.
, A comma is used.
blank A space is used.
-decimalpt=<decimal point>
Where decimal point is the decimal point you want to use. The decimal
point is used for numeric constants in SQL statements. Decimal point can
be any one of the following values:
Value Definition
. A period is used. This is the default.
, A comma is used.
-stmtCCSID=<CCSID>
Where CCSID is the coded character set identifier for the SQL statements
that are prepared into the package. The value of the job during
customization time is the default value.
-sorttbl=<library name/sort sequence table name>
Where library name/sort sequence table name is the location and table
name of the sort sequence table you want to use. The sort sequence table is
used for string comparisons in SQL statements. The library name and sort
sequence table name each have limits of 10 characters. The default value is
taken from the job during customization time.
-langID=<language identifier>
Where language identifier is the language identifier you want to use.
The default value for the language identifier is taken from the current job
during customization time. The language identifier is used in conjunction
with the sort sequence table.
For a more detailed information on any of the above fields, see DB2 for AS/400
SQL Programming, SC41-5611
To print the content of the profiles generated by the SQLJ translator in plain text,
use the profp utility as follows:
profp MyClass_SJProfile0.ser
Where MyClass_SJProfile0.ser is the name of the profile you wish to print.
To print the content of the DB2 customized version of the profile in plain text, use
the db2profp utility as follows:
db2profp MyClass_SJProfile0.ser
Where MyClass_SJProfile0.ser is the name of the profile you wish to print.
Note: If you run db2profp on an uncustomized profile, it will simply tell you that
the profile has not been customized. If you run profp on a customized profile, it
will display the contents of the profile without the customizations.
Where SQLJ profile name is the name of the profile to be printed and options is
the list of options you want.
Chapter 7. Accessing databases using AS/400 Developer Kit for Java DB2 SQLJ support 143
To install debugging class-auditors, enter the following at the Qshell command
prompt:
profdb MyClass_SJProfile0.ser
To run the profconv utility, type the following on the Qshell command line:
profconv MyApp_SJProfile0.ser
Where MyApp_SJProfile0.ser is the name of profile instance you wish to convert.
The profconvtool invokes sqlj -ser2class. See sqlj for command line options.
If you want to run your Java application on a host that does not have a
graphical user interface (GUI), such as an AS/400 system, you can either the
Remote Abstract Window Toolkit (AWT) or the Class Broker for Java (CBJ).
You use Remote AWT with install and administration interfaces of server
applications. These interfaces typically have a minimum of complex graphics and
highly-interactive content. Remote AWT distributes AWT processing between
AS/400 and a workstation. So, responsiveness of graphic-intensive and
highly-interactive operations are not as fast as AWT implementations on platforms
with locally-attached graphic terminals. To use Remote AWT, see setting up
Remote AWT.
You can use the CBJ for high performance GUI services. Since Remote AWT is not
recommended for complex graphics or highly-interactive operations, you can use
the CBJ instead, which was designed for these environments. To use CBJ, see
setting up CBJ.
You can use any graphics-capable hardware, including IBM Network Station, as a
remote display for Remote AWT if it meets these requirements:
v Graphics-capable hardware that runs Windows 95, Windows NT 4.0, IBM
Operating System/2 (OS/2), Sun Solaris, or AIX
v Configured hardware to access your AS/400 with TCP/IP
v Java Development Kit 1.1.x (JDK 1.1.7 or later is recommended) or J2SDK,
version 1.2.
To set up Remote AWT, complete these tasks:
1. Make the Remote AWT class files accessible to the remote display by copying
the files to the remote display or mapping the path to a network drive on the
remote display.
2. Add RAWTGui.zip or RAWTGui.jar to the CLASSPATH of the remote
displayFor JDK 1.1.x, add the RAWTGui.zip file to the CLASSPATH of the
remote display by setting the CLASSPATH environment variable or by using
the -classpath parameter of the java command. For J2SDK, version 1.2,
See Example: Setting up the Remote Abstract Window Toolkit for Java on a
Windows remote display, for an example of how to set up Remote AWT.
For more information about AWT, see the Abstract Window Toolkit by Sun
Microsystems, Inc.
To set up the Remote Abstract Window Toolkit (AWT) for Java on a Windows
remote display, do these tasks:
v Make the Remote AWT class files accessible to the remote display.
Copy the Remote AWT class files to the remote display. Copy
/QIBM/ProdData/Java400/jdk117/RAWTGui.zip to c:\rawt\RAWTGui.zip or
/QIBM/ProdData/Java400/jdk12/RAWTGui.jar to c:\rawt2\RAWTGui.jar
v Start the Remote AWT on the remote display by entering this on the command
line:
java -classpath c:\jdk1.1.7\lib\classes.zip;c:\rawt\RAWTGui.zip
java com.ibm.rawt.server.RAWTPCServer
or
java -jar c:\rawt2\RAWTGui.jar
Chapter 8. Running your Java application on a host that does not have a graphical user interface 147
v Use the -classpath parameter of the java command.
When you use the java command to start Remote AWT, you can use the
-classpath parameter to specify a CLASSPATH. The CLASSPATH includes the
path where the RAWTGui.zip file is located.
For example, in Windows, the CLASSPATH parameter may look like this:
-classpath c:\jdk1.1.7\lib\classes.zip;c:\rawt\RAWTGui.zip
J2SDK, version 1.2 JAR support sets the CLASSPATH, so you do not need
to explicitly set the CLASSPATH parameter. To set the classpath and start
Remote AWT on a remote display enter this command:
java -jar <PATH>RAWTGui.jar
where <PATH> is the fully qualified drive and directory where the RAWTGui.jar
file is located. For example, java -jar c:\rawt2\RAWTGui.jar.
Note: The Welcome dialog stays active when you start the server daemon. When
the Welcome dialog display closes, the server daemon ends. You can minimize the
Welcome dialog display while the server daemon is active and use the display to
end the server daemon.
To start the Remote Abstract Window Toolkit (AWT) server daemon for JDK 1.1.x,
enter this on the command line:
java com.ibm.rawt.server.RAWTPCServer
To start the Remote AWT server daemon for J2SDK, version 1.2, enter this on
the command line:
java -jar <PATH>RAWTGui.jar
where “PATH” is the fully qualified drive and directory where the RAWTGui.jar
file is located. For example, java -jar c:\rawt2\RAWTGui.jar .
The server daemon selects the first free port above 2000 when the Java application
connects using Remote AWT. The Java application uses this port until the
application ends. Additional Java applications are connected to subsequent free
ports above 2000. The available range of ports goes up to 9999.
For more information about setting up TCP/IP, see “How do I set up TCP/IP” in
m. Press Enter.
You can also run a Java program using Remote AWT with Netscape.
One option is to start the Remote Abstract Window Toolkit (AWT) server within
the Netscape Java virtual machine by opening an HTML file that contains
com.ibm.rawt.server.StartRAWT.class. For example, see the RAWT.html file below.
Once started, you can then start a Java application on your AS/400.
Or, you can start the Remote AWT server within the Netscape Java virtual machine
by opening an HTML file that contains com.ibm.rawt.server.StartRAWT400.class
and the AS/400 Toolbox for Java classes. For example, see the RAWT400.html file
shown below. Once started, you can sign on to your AS/400 where the Java
application resides and start the application.
Running within the Remote AWT server within the Netscape Java virtual
machine:
Chapter 8. Running your Java application on a host that does not have a graphical user interface 149
To run the Remote AWT server within the Netscape Java virtual machine follow
these steps:
1. Edit this example .html file for your specific installation information for
RAWTGui.zip. This file, RAWT.html, starts Remote AWT within the Netscape
Java virtual machine.
<HTML>
<BODY TEXT=“#000000” LINK=“#0000EE” VLINK=“#551A8B” ALINK=“#FF0000”>
<CENTER>
<APPLET CODE=“com.ibm.rawt.server.StartRAWT.class”
codebase=“file://C|remote_awt\jdk1.1.7\lib\RAWTGui.zip”
WIDTH=600 HEIGHT=50>
</APPLET>
</CENTER>
</BODY>
</HTML>
2. Browse the RAWT.html page with Netscape 4.05 or higher. After granting all of
the requested privileges, Netscape starts the Remote AWT server and runs it
within its Java virtual machine.
3. Start a Java application on your AS/400 using Remote AWT.
4. After you exit the application, click on the Reload button while pushing the
Shift key to start the Remote AWT server again.
Running the Remote AWT server within the Netscape Java virtual machine and
signing on to your AS/400:
To run the Remote AWT server within the Netscape Java virtual machine and sign
on to your AS/400 follow these steps:
1. Edit this example .html file for your specific installation information for
jt400.zip and RAWTGui.zip. This file, RAWT400.html, starts Remote AWT and
uses the AS/400 Toolbox for Java to sign on to AS/400.
<HTML>
<BODY TEXT=“#000000” LINK=“#0000EE” VLINK=“#551A8B” ALINK=“#FF0000”>
<CENTER>
<APPLET ARCHIVE=“file://C\jt400\lib\jt400.zip”
code=“com.ibm.rawt.server.StartRAWT400.class”
codebase=“file://C|remote_awt\jdk1.1.1\lib\RAWTGui.zip”
WIDTH=600 HEIGHT=50>
</APPLET>
</CENTER>
</BODY>
</HTML>
2. Browse this RAWT400.html page with Netscape 4.05. After granting all of the
requested privileges, Netscape starts the Remote AWT applet that displays a
panel where you can do any of these options:
v Sign on to your AS/400 with Remote AWT using AS/400 Toolbox for Java to
access AS/400.
v Enter the Java application name and arguments with Remote AWT
properties.
v Push the Start Application button to start the specified Java application with
Remote AWT.
You can select to print on the remote display or to an AS/400. A new print dialog
displays when an application issues a print request. The print request allows you
to select either a Remote Display printer or OS/400 printer. If you select OS/400
printer, a sign on dialog display appears. Once you have signed on, the Print
Dialog display appears. You can specify the OS/400 print queue, print file, file and
banner page title. You can also select paper size, orientation, and number of copies.
To use remote printing, you must install the AS/400 Toolbox for Java (5763-JC1)
and add this to your classpath on AS/400:
QIBM/ProdData/HTTP/Public/jt400/lib/jt400.zip
You can update the classpath by adding the classpath environment variable or by
using the classpath parameter.
Note:If this message appears while printing to AS/400, either the AS/400 Toolbox
for Java is not installed or the AS/400 Toolbox for Java classes are not in the
classpath.
Failed to load class file: com/ibm/as400/access/PrintObjectList.class
Exception occurred during event dispatching:
java.lang.NoClassDefFoundError: com/ibm/as400/access/PrintObjectList
Here are the default properties that are required for Remote AWT.
v java.awt.printerjob=com.ibm.rawt2.ahost.java.awt.print.AHPrinterjob
Remote AWT properties for remote display:
Chapter 8. Running your Java application on a host that does not have a graphical user interface 151
If the server daemon or Java application abnormally ends with this message, check
the Java version on your remote display.
The JDK version in the Application-host/User-station is incompatible with the Remote-AWT version...
To check the version level, enter java -version on the command line. You can use
this new property on a remote display if you have a problem with the JDK
version. This property is not applicable for the AS/400. If the version is not at level
1.1.x, then you must install the proper level. If it is at level 1.1.x, you can run the
Remote AWT server and or the Java application with this property that indicates
the Java version: -DJdkVersion=1.1.x.
You can either install CBJ yourself or have the system administrator install it for
you. If the system administrator installs the product, all programmers can share
the same Java code.
You can either install CBJ on Windows 95/98/NT, UNIX, or AS/400. In most
circumstances, you must install CBJ on your client machine and server machine.
Note:If your client machine is running a client applet that is accessed through a
web server on the server machine, then you do not need to install CBJ on the client
machine.
To install CBJ on AS/400, see Installing Class Broker for Java on AS/400.
“PATH” is the directory path where the cbj_1.1.jar package is located. For
example, QIBM/ProdData/Java400/ext.
The CBJ files are extracted into the subdirectory, named /usr/local/JCBroker.
See Package content of cbj_.1.1.jar for more information.
5. Create an Java program on AS/400 for jcb.jar, by entering this command:
CRTJVAPGM CLSF('/usr/local/JCBroker/lib/jcb.jar')
6. If you want to use the CBJ classes (not in debug mode), you have to add
JCBroker\lib and JCBroker\lib\jcb.jar to the classpath option in the Java
command line. We do not recommended that you add JCBroker\lib and
JCBroker\lib\jcb.jar to the CLASSPATH environment variable, because it
might conflict with class loading when you run applets that set applet_jcb.jar
in the ARCHIVE tag.
7. If you want to run CBJ in debug mode, replace jcb.jar with jcbd.jar in the
classpath or override the classpath value on the Java command line. You can
also use this command:
CRTJVAPGM CLSF('/usr/local/JCBroker/lib/jcbd.jar')
8. For more information on CBJ APIs, running demos, editing properties,
designing and writing CBJ applications, and other topics, refer to the
JCBroker/index.html file in the cpj_1.1.jar package.
Chapter 8. Running your Java application on a host that does not have a graphical user interface 153
3. Change to your directory (C:\) and enter this command:
C:\ > jar xvf cbj_1.1.jar
The CBJ files are extracted and are copied into the directory. See Package
content of cbj_.1.1.jar for more information.
4. If you want to use the CBJ classes (not in debug mode), add C:\JCBroker\lib
and C:\JCBroker\lib\jcb.jar to the classpath option on the Java command
line. Note:We do not recommended that you add it to the system CLASSPATH
environment variable, because it might conflict with class loading when
running applets that set applet_jcb.jar in the ARCHIVE tag.
5. To run CBJ in debug mode, replace jcb.jar with jcbd.jar in the classpath.
To install CBJ on UNIX follow the same step for Windows, except for the
following system dependent changes:
v Replace the Windows file separator “\” with the UNIX file separator “/”.
v Replace the Windows classpath separator “;” with the UNIX classpath
separator “:”.
v Replace the Windows system environment variables “%XXX%” with the
UNIX system environment variables “$XXX”.
6. For more information on CBJ APIs, running demos, editing properties,
designing and writing CBJ applications, and other topics, refer to the
JCBroker/index.html file in the cpj_1.1.jar package.
The next level of directories under the JCBroker directory consists of the this data:
demo
This directory contains these subdirectories: bin, binx, html, images, lib, log and
src. These directories contain the Windows executable, UNIX executable, HTML
pages, GIF files, class files, and source code (for some examples) of several demo
applications. You can run these demo examples by following the demo
instructions. The log directory is a placeholder for debug log files.
doc
This directory contains these two subdirectories: api and guide. The CBJ API guide
and a user guide about CBJ are stored here. The API documentation was generated
with the J2SDK, version 1.2, javadoc tool. To browse the API document or the user
guide, open the index.html file in the corresponding directory. The user guide is an
introductory level document, whereas the QuickStart guide is a fast track entry
document.
This directory also contains a FAQ.html file and the quickStart.html gile that
explains how to install and use CBJ, and shows you how to run the demo
examples.
lib
This directory contains the CBJ classes and resources that are needed for you to
develop, run, and deploy new CBJ based applications. The classes are packaged in
the jcb.jar file, For debug mode, the classes are packaged in the jcbd.jar file. The
classes that are included in the ARCHIVE tag of an applet are packaged in the
applet_jcb.jar file. For debug mode, the classes are packaged in the applet_ jcbd.jar
file. The JCB properties file, named JCB.properties, is in the
com/ibm/jcb/resources subdirectory. It is read by the CBJ runtime when started.
You can change this file to reflect your preferences. The properties are explained in
the installation and setting up section. The properties that only to applets are
contained in the applet_JCB.properties file, which is part of the applet_ jcb.jar and
applet_ jcbd.jar. You can also change this file to reflect your preferences when
running in applet mode. To change this file, run the Editor Java application that
resides in this directory.
Chapter 8. Running your Java application on a host that does not have a graphical user interface 155
src
This directory contains the CBJ source code and the internal version log file, called
version.log. The directory is empty except for selected packages.
index.html
This is the starting page that references you to the rest of the documentation.
You can use adopted authority to access objects with the authority of the user that
is running the program, and the program owner’s authority. Adopted authority
temporarily gives a user authority to objects that they would not have originally
had authority to access. See the Create Java Program (CRTJVAPGM) command
information for details on the two new adopted authority parameters, which are
USRPRF and USEADPAUT.
The bytecode loader and verifier, within the Java virtual machine, also provide a
measure of Java security using the Java security model. Just as with applets, the
bytecode loader and verifier check that the bytecodes are valid and data types are
used properly. They also check that registers and memory are accessed correctly,
and that the stack does not overflow or underflow. These checks ensure that the
Java virtual machine can safely run the class without compromising the integrity of
the system.
The Secure sockets layer (SSL) Java Standard Extension to JDK 1.1 is another item
of security supported by AS/400 Developer Kit for Java. SSL provides a means of
authenticating a server and a client to provide privacy and data integrity. All SSL
communication begins with a “handshake” between the server and the client.
During a handshake, SSL negotiates the cipher suite that the client and server use
to communicate with each other. This cipher suite is a combination of the various
security features available through SSL. The combination of a number of different
security features provides increased security for client and server communications.
The “sandbox” security model is a combination of the class loader, class file
verifier, and the java.lang.SecurityManager class.
book .
You may be limited on the Cryptographic Access Provider that you can choose
from, depending on which country you are in. Once you load a Cryptographic
Access Provider, you can use any of the cipher suites that that Access Provider
offers.
If you do not want to use your system’s default certificate, you need to choose a
different certificate to use. You can choose from two types of certificates:
v User certificate that identifies the user of the application.
v System certificate that identifies the system on which the application is running.
These questions can help you decide whether to use a user certificate or a system
certificate:
v Does your Java application run as a client application or a server application?
– If your application runs as a client application, you probably want to use a
user certificate.
– If your application runs as a server application, you probably want to use a
system certificate.
v Do you want the certificate to identify the user who is working with the
application or the system on which the application is running?
– If you want the certificate to identify the user who is working with the
application, then you want to use a user certificate.
– If you want the certificate to identify on which system the application is
running, then you want to use a system certificate.
Once you know what kind of certificate you need, you can choose from any of the
digital certificates in any of the certificate containers that you are able to access.
If you have not already decided which digital certificate to use, see deciding which
digital certificate to use. You may also decide to use your system’s default
certificate, which is stored in the system’s default certificate container.
To use your system’s default digital certificate, you do not need to specify a
certificate or a certificate container anywhere. Your Java application uses your
system’s default digital certificate automatically.
For example, if the name of the certificate you want to use is MYCERTIFICATE,
then the java command you enter would look like this:
java -os400.certificateLabel=MYCERTIFICATE MyClass
In this example, the Java application MyClass would use the certificate
MYCERTIFICATE. MYCERTIFICATE would need to be in the system’s default
certificate container in order to be used by MyClass.
For example, if the name of the certificate container that contains the digital
certificate you want to use is named MYDCC, then the java command you enter
would look like this:
java -os400.certificateContainer=MYDCC MyClass
In this example, the Java application, named MyClass.class, would run on the
system by using the default digital certificate that is in the digital certificate
container named MYDCC. Any sockets that you create in the application use the
default certificate that is in MYDCC to identify themselves and make all of their
communications secure.
See Examples: Modifying your Java code to use server socket factories for an
example of a client program being converted to use socket factories.
See Example: Modifying your Java code to use client socket factories for an
example of a client program being converted to use socket factories.
For background information, see modifying your code to use socket factories.
For background information, see modifying your code to use socket factories.
See Examples: Modifying your Java client to use secure sockets layer and
Examples: Modifying your Java server to use secure sockets layer for example
code.
The first example shows you the factorySocketServer class not using SSL. The
second example shows you the same class, renamed factorySSLSocketServer, using
SSL.
For background information, see modifying your Java code to use secure sockets
layer.
The first example shows you the factorySocketClient class not using SSL. The
second example shows you the same class, renamed factorySSLSocketClient, using
SSL.
For background information, see modifying your Java code to use secure sockets
layer.
Java locales
A locale is a geographic or political region of the world that shares the same
language and customs. In Java, the Locale class represents a locale.
The AS/400 Developer Kit for Java supports these locales. The AS/400 job
LANGID and CNTRYID determine the default locale. See Java system properties
for more details.
These property files are required for the ResourceBundleExample program to work
as intended:
Contents of RBExample.properties
Hello.text=Hello
Contents of RBExample_de.properties
Hello.text=Guten Tag
Contents of RBExample_fr_FR.properties
Hello.text=Bonjour
For examples of PEX reports, see the Performance Tools/400, SC41-4340 book.
If the CRTJVAPGM command is not used before running a Java class file, JAR file,
or ZIP file, then the Java code runs more slowly the first time, because an
optimized Java program at optimization level 10 is created. Future runs will be
much faster because the Java program is saved and remains associated with the
class file or JAR file. Running the bytecodes interpretively may provide acceptable
performance during application development, but you may want to use the
CRTJVAPGM command before running the Java code in a production environment.
If your program is running slowly, enter the Display Java Program (DSPJVAPGM)
command to view the attributes of a Java program.
At optimization level 40, some Java program optimizations are not 100 percent
Java compatible. Thus, a few programs that do not run at level 40, may run at
level 30 instead. You can run programs that do not run at optimization level 40 by
using licensed internal code optimization LICOPT parameter strings. However,
performance at level 30 may be sufficient for your program.
If you are having problems running Java code that seemed to work on another
Java virtual machine, try using optimization level 30 instead of level 40. If this
works, and your performance is acceptable, you do not need to do anything else. If
you need better performance, see LICOPT parameter strings for information on
how to enable and disable various forms of optimization. For example, you could
first try creating the program using OPTIMIZE(40) LICOPT(NoPreresolveExtRef). If
your application contains dead calls to classes that are not available, this LICOPT
value allows your program to run without problems.
To determine what level of optimization your Java programs were created at, you
can use the Display Java Program (DSPJVAPGM) command. To change the
optimization level of your Java program, use the Create Java Program
(CRTJVAPGM) command.
The Java transformer enables inlining for optimization level 30 and optimization
level 40. Optimization level 30 enables some inlining of final methods within a
single class. Optimization level 40 enables inlining of final methods within a ZIP
file or JAR file. You can control method inlining with the AllowInlining and
NoAllowInlining LICOPT parameter strings. The AS/400 interpreter does not
perform method inlining.
Chapter 11. Tuning Java program performance with the AS/400 Developer Kit for Java 177
Java exception performance considerations
AS/400 exception architecture allows versatile interrupt and retry capabilities. It
allows mixed language interaction. Throwing Java exceptions on AS/400 may be
more expensive than on other platforms. This should not affect overall application
performance unless Java exceptions are routinely used in the normal application
path.
For a complete description of the Java events, see the Performance Tools/400,
SC41-4340 book.
Call/return trace output produced with the Print Performance Explorer Report
(PRTPEXRPT) command shows the central processing unit (CPU) time for each call
for every Java method that is traced. In some cases, you may not be able to enable
all of the class files for call return tracing. Or, you may be calling native methods
and system functions that are not enabled for tracing. In this situation, all of the
CPU time that is spent in these methods or system functions accumulates. Then, it
is reported to the last Java method that is called and has been enabled.
Note: CPU profiling does not show relative CPU usage for Java programs that are
interpreted.
Chapter 11. Tuning Java program performance with the AS/400 Developer Kit for Java 179
3. Prepare the Java program to report program events to the AS/400 Performance
Data Collector. You can do this by using the Create Java Program
(CRTJVAPGM) command on any Java program that you want to report
performance data on. You must create the Java program by using the
ENBPFRCOL(*ENTRYEXIT) parameter.
Note: You must repeat this step for every Java program that you want to collect
performance data on. If you do not perform this step, no performance data is
collected by the PEX and no output is produced by running the Java
Performance Data Converter (JPDC) tool.
4. Start the PEX data collection by using the Start Performance Explorer (STRPEX)
command.
5. Run the program that you would like to analyze. This program should not be
in a production environment. It will generate a large amount of data in a small
amount of time. You should limit the collection time to five minutes. A Java
Program that runs for this amount of time generates a lot of PEX system data.
If too much data is collected, an unreasonable amount of time is required to
process the data.
6. End the PEX data collection by using the End Performance Explorer (ENDPEX)
command.
Note: If this is not the first time that you have ended PEX data collection, you
must specify a replace file of *YES or it will not save your data.
7. Run the JPDC tool.
8. Connect the integrated file system directory to the system with the viewer of
your choice: java_g -prof viewer or Jinsight viewer. You can copy this file from
AS/400 and use it as input to any suitable profiling tool.
For information on how collect Java performance data, see collecting Java
performance data.
Note: The JDPC tool does not produce readable output. Use a Java profiling tool
that accepts java_g -prof or Jinsight data to analyze your data.
The JDPC tool accesses the AS/400 Performance Explorer (PEX) data that DB2/400
(using JDBC) stores. It converts the data to either Jinsight or general performance
types. Then, JDPC stores the output file in the integrated file system at a
user-specified location.
Note: You must follow appropriate AS/400 PEX data collection procedures to
collect PEX data while running your specified Java application on AS/400. You
must set a PEX definition with defines the entrance and exit of a program or a
collect and store procedure. For details on how collect PEX data and set a PEX
For information on how to run JPDC, see Running the Java Performance Data
Converter.
You can start the JPDC program by using either the Qshell command line interface
or Run Java (RUNJVA) command.
Chapter 11. Tuning Java program performance with the AS/400 Developer Kit for Java 181
To operate this code the /QIBM/ProdData/Java400/ext/JPDC.jar file must be in
the Java classpath on AS/400. When the program is done running, a text output
file can be found in the current directory.
You can run JPDC by using the AS/400 command line or Qshell environment. See
Example: Running the Java Performance Data Converter for details.
The interface between the two jobs is established when you specify the *DEBUG
option on the Run Java (RUNJVA) command.
For more information about the system debugger, see the ILE C Programmer’s
To use the *DEBUG option, enter the Run Java (RUNJVA) command that is
followed by the name of your classfile and OPTION(*DEBUG) on the command
line. For example, the AS/400 command line should look like this:
RUNJVA CLASS(classname) OPTION(*DEBUG)
Note: If you are not authorized to use the Start Service Job (STRSRVJOB)
command, OPTION(*DEBUG) is ignored.
To view the debugging displays, see Initial debugging displays for Java programs.
Setting breakpoints
The running of a program can be controlled with breakpoints. Breakpoints stop a
running program at a specific statement.
To set breakpoints:
1. Place the cursor on the line of code where you would like to set a breakpoint.
2. Press F6 (Add/Clear breakpoint) to set the breakpoint.
3. Press F12 (Resume) to run the program.
Note:Just before the line of code runs, where the breakpoint is set, the program
source is displayed indicating that the breakpoint was hit.
+————————————————————————————————————————+
| Display Module Source |
| |
Chapter 12. Debugging programs using the AS/400 Developer Kit for Java 185
|Current thread: 00000019 Stopped thread: 00000019 |
|Class file name: Hellod |
|35 public static void main(String[] args) |
|36 { |
|37 int i,j,h,B[],D[][]; |
|38 Hellod A=new Hellod(); |
|39 A.myHellod = A; |
|40 Hellod C[]; |
|41 C = new Hellod[5]; |
|42 for (int counter=0; counter<2; counter++) { |
|43 C[counter] = new Hellod(); |
|44 C[counter].myHellod = C[counter]; |
|45 } |
|46 C[2] = A; |
|47 C[0].myString = null; |
|48 C[0].myHellod = null; |
| |
|49 A.method1(); |
|Debug . . . |
| |
|F3=End program F6=Add/Clear breakpoint F10=Step F11=Display variable |
|F12=Resume F17=Watch variable F18=Work with watch F24=More key |
|Breakpoint added to line 41. |
+————————————————————————————————————————+
When you hit a breakpoint, if you want to set breakpoints that are only hit within
the current thread, use the TBREAK command.
For more information about system debugger commands, see the ILE C
When the program source first displays, you can start stepping. The program stops
before running the first statement. Press F10 (Step). Continue to press F10 (Step) to
step through the program. Press F22 (Step into) to step into any function that your
program calls. You can also start stepping anytime a breakpoint is hit. For
information about setting breakpoints, see Setting breakpoints.
+————————————————————————————————————————+
| Display Module Source |
| |
|Current thread: 00000019 Stopped thread: 00000019 |
|Class file name: Hellod |
|35 public static void main(String[] args) |
|36 { |
|37 int i,j,h,B[],D[][]; |
|38 Hellod A=new Hellod(); |
|39 A.myHellod = A; |
|40 Hellod C[]; |
|41 C = new Hellod[5]; |
|42 for (int counter=0; counter<2; counter++) { |
To stop stepping and continue running the program, press F12 (Resume).
For more information about stepping, see the ILE C Programmer’s Guide,
Chapter 12. Debugging programs using the AS/400 Developer Kit for Java 187
v If you want to see the contents of a variable that is a data member of a class,
you can specify classvariable.membername.
v If you try to evaluate a variable before it has been initialized one of two things
can happen. Either a Variable not available to display message is shown, or
the unitialized contents of the variable are shown, which could be a strange
value.
If you set the environment variable to 1 when the Run Java (RUNJVA) command
runs, a message is sent to the user’s message queue. The message is sent before the
Java virtual machine starts in the BCI job. The message looks like this:
Spawned (child) process 023173/JOB/QJVACMDSRV is stopped (G C)
The BCI job waits until you enter a reply to this message. A reply of (G) starts the
Java virtual machine.
You can set breakpoints in a *SRVPGM or *PGM, which the BCI job calls, before
replying to the message.
Note: You cannot set breakpoints in a Java class, because at this point, the Java
virtual machine has not been started.
Chapter 12. Debugging programs using the AS/400 Developer Kit for Java 189
Debugging servlets
Debugging servlets is more complicated than debugging regular Java
applications, since servlets run in the Java runtime of the IBM HTTP Server.
There are two ways to find the job log for the BCI job. You can find the name of
the BCI job that is logged in the job log of the job that ran the Java command.
Then, use that job name to find the job log for the BCI job.
You can also find the job log for the BCI job by following these steps:
1. Enter the Work with Submitted Jobs (WRKSBMJOB) command on the AS/400
command line.
2. Go to the bottom of the list.
3. Look for the last job in the list, called QJVACMDSRV.
4. Enter option 8 (Work with Spooled Files) for that job.
5. A file called QPJOBLOG displays.
6. Press F11 to see view 2 of the spooled files.
7. Verify that the date and time match the date and time when the failure
occurred.
Note:If the date and time do not match the date and time when you signed off,
continue looking through the list of submitted jobs. Try to find a
QJVACMDSRV job log with a date and time that matches when you signed off.
If you are unable to find a job log for the BCI job, one may not have been
produced. This happens if you set the ENDSEP value for the QDFTJOBD job
description too high or the LOG value for the QDFTJOBD job description specifies
*NOLIST. Check these values, and change them so that a job log is produced for
the BCI job.
To produce a job log for the job that ran the Run Java (RUNJVA) command.
1. Enter SIGNOFF *LIST.
2. Then, sign back on.
If possible, save the source files for any Java classes that are involved in the
problem. This is helpful to IBM when reproducing and analyzing the problem.
4. Save any service programs that contain native methods that are needed to run
the program.
5. Save any data files that are needed to run the Java program.
6. Add a complete description of how to reproduce the problem. This should
include:
v The value of the CLASSPATH environment variable.
v A description of the Java command that was run.
v A description of how to respond to any input that is required by the
program.
7. Include any vertical licensed internal code (VLIC) logs that have occurred near
the time of failure.
8. Add the job log from both the interactive job and the BCI job where the Java
virtual machine was running.
information that is provided at IBM AS/400 Home Page under the topic
“Support” for more information. Use IBM Support Services for 5769-JV1 (AS/400
Developer Kit for Java). Or, contact your local IBM representative.
You may, at IBM direction, be required to obtain a more current level of the
AS/400 Developer Kit for Java to receive Continued Program Services. For more
information, see support for multiple Java Development Kits (JDKs).
Resolving defects of the AS/400 Developer Kit for Java program are supported
under program services or voice support. Resolving application programming or
debugging issues are supported under consulting services.
The AS/400 Developer Kit for Java application program interface (API) calls are
supported under consulting services, unless:
1. It is clearly a Java API defect as demonstrated by re-creation in a relatively
simple program.
2. It is a question that asks for documentation clarification,
3. It is a question about the location of samples or documentation.
All programming assistance is supported under consulting services. This includes
the program samples that are provided in the AS/400 Developer Kit for Java
licensed program (LP) product. Additional samples may be available on the
The AS/400 Developer Kit for Java LP provides information about solving
problems. If you believe that there is a potential defect in the AS/400 Developer
Kit for Java API, a simple program that demonstrates the error is required.
Chapter 13. Troubleshooting the AS/400 Developer Kit for Java 193
194 AS/400 Developer Kit for Java
Chapter 14. Code examples for the AS/400 Developer Kit for
Java
CL Commands:
v CRTJVAPGM
v CHGJVAPGM
v RUNJVA
v DLTJVAPGM
v DMPJVM
v DSPJVAPGM
Other Programming Languages:
v Calling another Java program
v Calling a CL program
v Calling a CL command
v Input and output streams
v Sockets
v Calling Java from C
v Calling Java from RPG
v Invocation API
JDBC:
v Connecting
v Statement interface
v PreparedStatement interface
v CallableStatement interface
v ResultSet interface
v DatabaseMetaData interface
v JDBC application
v Embedding SQL Statements
SQLJ:
v Embedding SQL Statements in your Java application
Remote Abstract Window Toolkit:
v Setting up Remote AWT
Secure sockets layer:
v Socket factories
v Server socket factories
v Secure sockets layer
v Secure sockets layer server
Internationalization:
v DateFormat
v NumberFormat
v ResourceBundle
Printed in U.S.A.