ERserver
iSeries
Getting started with Java on IBM iSeries: Using the IBM
Developer Kit for Java
ERserver
iSeries
Getting started with Java on IBM iSeries: Using the IBM
Developer Kit for Java
© Copyright International Business Machines Corporation 1998, 2001. All rights reserved.
US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract
with IBM Corp.
Contents
Setting up Java on iSeries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Installing the licensed programs for Java on iSeries . . . . . . . . . . . . . . . . . . . . 1
IBM Developer Kit for Java overview . . . . . . . . . . . . . . . . . . . . . . . . . 2
Sun Microsystems, Inc. Java Development Kit . . . . . . . . . . . . . . . . . . . . 2
Java packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Qshell Interpreter and Java . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Installing a licensed program with the Restore Licensed Program command for Java on iSeries 3
Creating a Java application for your iSeries . . . . . . . . . . . . . . . . . . . . . . 4
Mapping a network drive to iSeries . . . . . . . . . . . . . . . . . . . . . . . . 4
Creating a directory on your iSeries . . . . . . . . . . . . . . . . . . . . . . . . 6
Writing a Java application on your workstation . . . . . . . . . . . . . . . . . . . . 6
Writing your Java program on iSeries . . . . . . . . . . . . . . . . . . . . . . . 7
Creating the Java source code . . . . . . . . . . . . . . . . . . . . . . . . . 7
Copying your Java code to a stream file . . . . . . . . . . . . . . . . . . . . . 8
Compiling your Java application from Qshell Interpreter . . . . . . . . . . . . . . . . . 9
Optimizing your Java application . . . . . . . . . . . . . . . . . . . . . . . . . 9
Running your Java application from Qshell Interpreter . . . . . . . . . . . . . . . . . 10
Fixes for Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
What you can do with Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
IBM WebSphere Application Server overview . . . . . . . . . . . . . . . . . . . . . 12
Servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Applets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
The Java platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Java applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Java virtual machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Java class files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Java JAR files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Java interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Java threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Java for e-business. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Defining e-business. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Solution scenario for e-business . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Other information about Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Java education . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Java and IBM iSeries references . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Getting started with Java Feedback . . . . . . . . . . . . . . . . . . . . . . . . 19
© Copyright IBM Corp. 1998, 2001 iii
iv iSeries: Getting started with Java on IBM iSeries: Using the IBM Developer Kit for Java
Setting up Java on iSeries
To create your first Java application on iSeries, complete the following steps:
1. Install the licensed programs
2. Create a Java application
More information about Java
Use the IBM Developer Kit for Java information to find the resources and tips you need to create Java
applications. To keep current with the latest technologies and innovations, see Other information about
Java for links and other resources.
Installing the licensed programs for Java on iSeries
To program Java on iSeries, you must install IBM Developer Kit for Java. You could also choose to install
the Qshell Interpreter, which provides a UNIX-like shell environment that supports standard Java
commands.
To install these licensed programs, follow these steps:
1. At the command prompt, type:
GO LICPGM
Press Enter.
The Work with Licensed Programs display appears.
2. Select option 11. Install licensed programs to install the licensed programs.
3. Scroll through the list by pressing the PageDown key. Find licensed program 5722-JV1 . Notice
that 5722-JV1 has six entries, a base component (IBM Developer Kit for Java) and several product
options, as shown below:
5722JV1 *BASE IBM Developer Kit for Java
5722JV1 3 Java Developer Kit 1.2
5722JV1 4 Java Developer Kit 1.1.8
5722JV1 5 Java Developer Kit 1.3
4. Type a 1 (Install) in the Option field for licensed program 5722-JV1 *BASE. Also, select the Java
Developer Kit (JDK(TM)) you want to install, and type a 1 in the Option field next to it.
The IBM Developer Kit for Java provides support for multiple JDKs. You can install a combination of
options and program with any JDK. More than one option can be installed at once. If your Java
program does not specify which JDK version to use, a default JDK is selected.
If the option that you want to install is not displayed in the list, you can add it to the list by entering
a 1 (Install) in the blank field at the top of the Option column. Type 5722JV1 in the Licensed Program
field and your option number in the Product Option field.
For more information about multiple JDK versions and IBM Developer Kit for Java, see the IBM
Developer Kit for Java topic.
Note: You may have to scroll through several pages to find the licensed program you are looking for.
To find out if a licensed program has been installed, press F11 (Display status/release) on the Install
Licensed Programs display. An installed licensed program displays *COMPATIBLE in the Installed
Status field.
If IBM Developer Kit for Java or QShell Interpreter do not appear on the Install Licensed Programs
menu, you need to use the restore licensed programs (RSTLICPGM) method to install the licensed
programs from CD-ROM, disk, or tape.
5. Find 5722-SS1 Option 30, OS/400 - QShell Interpreter . If it has not yet been installed, type 1
(Install) in the Option field.
© Copyright IBM Corp. 1998, 2001 1
6. Press Enter. The programs will begin installing.
When the licensed programs are finished installing, the Work with Licensed Programs display appears
again.
IBM Developer Kit for Java overview
The IBM Developer Kit for Java is optimized for use in an iSeries server environment. It allows you to
create and run Java programs on iSeries. The IBM Developer Kit for Java is a compatible implementation
of the Sun Microsystems, Inc. Java Technology, and functions much like their Java Development Kit
(JDK(TM)). It provides core classes, utilities, tools, and a Java run time environment.
For more information about IBM Developer Kit for Java, see the IBM Developer Kit for Java topic.
Sun Microsystems, Inc. Java Development Kit
The Java Development Kit (JDK(TM)) is software that is distributed by Sun Microsystems, Inc. for Java
developers. It includes the Java interpreter, Java classes, and Java development tools: compiler,
debugger, disassembler, appletviewer, stub file generator, and documentation generator.
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 IBM Developer Kit for Java on
your iSeries by using either of the following commands:
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 Java Technology
java.sun.com for specific documentation. The IBM Developer Kit for Java is a compatible
implementation of the Sun Microsystems, Inc. Java Technology, so you should be familiar with their JDK
documentation.
For more specific details on Sun Microsystems, Inc. Java Development Kit, see these topics:
v Java packages lists the packages that are available as part of Sun Microsystems, Inc. JDK.
v Java tools is a reference table that lists the tools that Sun Microsystems, Inc. JDK supplies.
v Native methods and the Java Native Interface defines what a native method is and what these methods
do. This topic also briefly explains the Java Native Interface.
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 any 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 export classes
java.lang Core language classes
2 iSeries: Getting started with Java on IBM iSeries: Using the IBM Developer Kit for Java
Package Contents
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.
Java tools: For a complete list of tools that Sun Microsystems, Inc. Java Development Kit supplies, see
Tools Reference by Sun Microsystems, Inc. For more information about each individual tool that the IBM
Developer Kit for Java supports, see Java tools that are supported by the IBM Developer Kit for Java.
Qshell Interpreter and Java
You might have written some Java programs on other platforms, like Windows or UNIX. If so, you know
the standard Java commands such as java, javac, jdb, and rmic. And, if you are familiar with OS/400,
you know that CL commands are unique.
If you want to know how standard Java commands and OS/400 commands can work together, the answer
is Qshell Interpreter. Qshell Interpreter provides a UNIX-like command environment, or shell (in fact, Qshell
closely resembles the UNIX Korn shell). Install Qshell Interpreter, and you can run the standard Java
commands and OS/400 commands from the same environment. Qshell Interpreter is not required for
running Java on iSeries, but it helps.
For more information about Qshell Interpreter, see the Qshell Interpreter topic.
Installing a licensed program with the Restore Licensed Program command for
Java on iSeries
The programs listed in the Install Licensed Programs display are those supported by the LICPGM
installation when your system was new. Occasionally, new programs become available which are not listed
as licensed programs on your system. If this is the case with the program you want to install, you must
use the Restore Licensed Program (RSTLICPGM) command to install it.
To install a licensed program with the Restore Licensed Program (RSTLICPGM) command, follow these
steps:
1. Put the tape or CD-ROM containing the licensed program in the appropriate drive.
2. On the iSeries command line, type:
RSTLICPGM
and press the Enter key.
The Restore Licensed Program (RSTLICPGM) display appears.
3. In the Product field, type the ID number of the licensed program you want to install.
4. In the Device field, specify your install device.
Setting up Java on iSeries 3
Note: If you are installing from a tape drive, the device ID is usually in the format TAPXX, where XX is
a number, like 01.
5. Keep the default settings for the other parameters in the Restore Licensed Program display. Press the
Enter key.
6. More parameters appear. Keep these default settings also. Press the Enter key. The program will
begin installing.
When the licensed program is finished installing, the Restore Licensed Programs display appears again.
Creating a Java application for your iSeries
You can create a Java application that runs on your server by using any of several different methods.
However, the easiest method is to write your Java applications on your workstation and save them on your
iSeries through a mapped network drive.
Developing Java applications on your workstation allows you to take advantage of one the numerous
graphical-based integrated development environment (IDE) products for Java and other programming tools
that are currently on the market.
How to create a Java application
To create a Java application, follow these steps:
1. Map a network drive to your iSeries
2. Create a directory on your iSeries for your Java applications
3. Write your Java application on your workstation
If you cannot map a network drive to your iSeries, you can write a Java application on your iSeries.
4. Compile your Java application from Qshell Interpreter
5. Optimize your Java application from Qshell Interpreter
6. Run your Java application from Qshell Interpreter
You can also easily compile, optimize, and run your Java application using Operations Navigator, a
graphical user interface for performing tasks on iSeries. For instructions, see Work with Java applications
using Operations Navigator. For more information on Operations Navigator, including installation
information, see Getting Started with Operations Navigator.
Mapping a network drive to iSeries
To map a network drive to iSeries, make you that you have Client Access Express for Windows installed
on your server and on your workstation. For more information on how to install and configure Client
Access Express, see Installing Client Access Express.
You must have a connection configured for the iSeries system before you can map a network drive.
To map a network drive, follow these steps:
1. Open Windows Explorer:
a. Right-click the Start button on your Windows taskbar.
b. Click Explore in the menu.
2. Select Map Network Drive from the Tools menu.
4 iSeries: Getting started with Java on IBM iSeries: Using the IBM Developer Kit for Java
3. Select the drive that you want to use to connect to your iSeries.
4. Type the path name to the your server. For example:
\\MYSERVER
where MYSERVER is the name of your iSeries system.
Setting up Java on iSeries 5
5. Check the Reconnect at logon box if it is blank.
6. Click OK to finish.
Your mapped drive will now appear in the All Folders section of Windows Explorer.
Creating a directory on your iSeries
You need to create a directory on your iSeries where you can save your Java applications. There are two
ways to do this:
v Create a directory using Operations Navigator
Choose this option if you have Client Access Express installed. If you plan to use Operations Navigator
to compile, optimize, and run your Java program, you must select this option to ensure your program is
saved in the correct location to perform these operations.
v Create a directory using the command entry line
Choose this option if you do not have Client Access Express installed.
For information about Operations Navigator, including installation information, see Getting Started with
Operations Navigator.
Writing a Java application on your workstation
If you have an integrated development environment (IDE) product installed on your workstation, use it to
code your Java application. See the instructions that came with your software for information on creating a
Java application.
If you do not have an IDE or other programming software, you can always code your Java application into
any text-based editor, such as Windows Notepad.
6 iSeries: Getting started with Java on IBM iSeries: Using the IBM Developer Kit for Java
However you code your application, save it in the directory you created on your iSeries, which you access
through the drive you have mapped to your server. Make sure you follow the Java naming convention
when you choose the name of your application.
Writing your Java program on iSeries
To write a Java program on your iSeries, follow these steps:
1. To create the source physical file, which is where your Java source code will be saved, you will first
need to create a library in which to save the file.
Note: On iSeries, libraries are not equivalent to directories. The system does not allow you to save a
source physical file in a directory. You must save the file in a library.
Create a library by typing this command on the command line:
CRTLIB LIB(mylib)
where mylib is the name of the library you are creating.
Press the Enter key.
A message appears at the bottom of your display, stating Library created.
2. Create the source physical file for your Java program by typing:
CRTSRCPF FILE(mylib/myfile)
where mylib is the name of the library you created in the previous step and myfile is the name of the
file you are creating.
Note: When choosing a name for the source physical file, you do not have to follow Java file naming
conventions (for example, naming your Java application after the class that is instantiated). The file
you are creating here acts only as a receptacle for your Java source code. You can create another file
for the source code later.
Press the Enter key.
A message appears at the bottom of your screen, stating File MYFILE created in library MYLIB.
3. Create the source code for the file using PDM.
4. Copy the source code to a stream file in your directory. Java applications must reside in a directory in
the integrated file system. If you copy your source code to a stream file, you can save it in your
directory.
Creating the Java source code: Now that you have created the source physical file, you need to add
the code. This part of the setup uses PDM (Programming Development Manager) to create the code and
manipulate the file.
1.
2. Start PDM. On the command line, type:
STRPDM
and press the Enter key.
The Programming Development Manager (PDM) display appears.
3. The source code for your file is associated with a source member of the file. Create and edit the
source member. Type 3 for Work with members and press the Enter key.
The Specify Members to Work With display appears.
4. Fill out the display as shown below:
File . . . . . . . . . . myfile
Library . . . . . . . . mylib
where myfile is the name of the file you created, and mylib is the name of the library in which you
saved the file.
Press the Enter key.
5. Press F6 to Create the file member.
Setting up Java on iSeries 7
Edit the source member. The Start Source Entry Utility (STRSEU) display appears.
6. Fill out the display as shown below:
Source file . . . . . . . . . . > myfile
Library . . . . . . . . . . . > mylib
Source member . . . . . . . . . myclass
Source type . . . . . . . . . . TXT
where myfile is the name of your Java program, mylib is the name of the library in which you saved it,
and myclass is the name of the file member you are creating.
Note: You may want to replace myclass with an abbreviated form of your Java class name.
Press the Enter key.
A message appears at the bottom of your display, stating Member MYCLASS added to file
mylib/MYCLASS. The SEU Edit display also reappears.
7. In the Edit display, without pressing the Enter key, type your Java program code.
Press the Enter key.
The End of data line appears immediately below the line you typed.
Press F3 to exit the Edit display.
8. Save the source member. The Exit display appears. Fill out the display as shown below:
Change/create member . . . . . . . Y
Member . . . . . . . . . . . . . myclass
File . . . . . . . . . . . . . . myfile
Library . . . . . . . . . . . .
mylib
Print member . . . . . . . . . . . N
Return to editing . . . . . . . . . N
Go to member list . . . . . . . . . N
where myclass is the name of your Java program, where myfile is the name of your physical source
file, and where mylib is the name of the library in which you saved your file.
Press the Enter key.
The Work with Members Using PDM display appears.
9. Exit PDM by pressing F3 twice.
Copying your Java code to a stream file: Before you can compile and run your Java application, you
must save it in a directory in the integrated file system. To save your Java source code in a directory, you
must copy the code to a stream file:
1. On the command line, type:
CPYTOSTMF
and press the F4 key.
The Copy To Stream File (CPYTOSTMF) display appears.
2. Fill out the display as shown below:
3.
From database file member . . .
’/QSYS.LIB/mylib.LIB/myfile.FILE/myclass.MBR’
To stream file . . . . . . . . .
’/mydir/myjavaclass.java’
Stream file option . . . . . . . *NONE
Data conversion options . . . . *AUTO
Database file CCSID . . . . . . *FILE
Stream file code page . . . . . 819
8 iSeries: Getting started with Java on IBM iSeries: Using the IBM Developer Kit for Java
Note: Entering 819 in the Stream file code page field saves the file as ASCII.
where mylib is the name of the library you created, myfile is the name of your file, and myclass is the
name of the source member you created for your source code.
Replace mydir with the name of the directory in which you want to save your Java program, and
replace myjavaclass with the class name of your Java application.
Note: See Name your Java application for more information on the Java file naming convention.
Press Enter twice.
A message appears at the bottom of your screen, stating Database file member copied to object.
Stream file: A stream file contains a continuous stream of data, similar to UNIX and Windows files. The
source physical file you created is a structured iSeries database file. To compile your Java application, it
must be in a format the Java compiler recognizes, which is a stream file.
Compiling your Java application from Qshell Interpreter
To compile and run your Java application on iSeries, use the Qshell Interpreter. Qshell is a UNIX-like
command entry environment that allows you to run the standard Java commands, such as javac and java,
on your server.
Follow these steps to compile your Java application:
1. Go to the Qshell Command Entry display. On the command line, type:
2. QSH
and press the Enter key.
The QSH Command Entry display appears.
3. Make the directory that contains your Java application the current directory.
On the Qshell command line, type:
cd /mydir
where mydir is the name of the directory in which you saved your Java application.
Press the Enter key.
4. Compile your Java application.
5. On the Qshell command line, type:
javac myclass.java
where myclass is the name of your Java application.
Press the Enter key.
After your application is finished compiling, the shell prompt (by default, a $) appears, signalling that
Qshell is ready for another command.
Optimizing your Java application
You have the option to optimize your Java application with the Create Java Program (CRTJVAPGM)
command.
CRTJVAPGM creates a hidden service program, associated with your class file, that improves
performance. CRTJVAPGM also has an OPTIMIZE parameter that allows you to select the level of
optimization for your service program. You should run the CRTJVAPGM command on all Java classes and
JAR files you create. By running CRTJVAPGM and optimizing your Java applications, you can make use
of just-in-time (JIT) compilers. JITs compile code as you need it, making them more efficient than direct
execution. For more information about JITs, see the IBM Developer Kit for Java information.
To optimize your Java application, follow these steps:
Setting up Java on iSeries 9
1. On the QSH Command Entry line, type:
system ″CRTJVAPGM ’/mydir/myclass.class’ OPTIMIZE(20)″
where mydir is the path name of the directory in which your Java application is saved, and where
myclass is the name of your compiled Java application.
Note: You can specify an optimization level of up to 40. An optimization level of 40 increases the
efficiency of the Java application, but it also limits debug capabilities. In the early stages of developing
a Java application, you may want to set your optimization level at 20 so you can more easily debug
your application. See the IBM Developer Kit for Java information for more about the CRTJVAPGM
command and the OPTIMIZE parameter.
2. Press the Enter key.
A message appears, stating that a Java program has been created for your class.
Running your Java application from Qshell Interpreter
To run your Java application on your iSeries:
1. On the Qshell command line, type:
java myclass
where myclass is the name of your compiled Java application.
Press the Enter key.
2. Your Java application runs. After it is finished, the shell prompt (by default, a $) appears, signalling that
Qshell is ready for another command.
Fixes for Java
It is a good idea to be aware of what fixes (or program temporary fixes, called PTFs) are needed to run
your server successfully. Ensure that you always have the latest fixes installed and applied on your server.
Use the links below to find the most current fix information for the following products:
v IBM Toolbox for Java
v WebSphere Application Server
Also, it is recommended that every two months you request the latest fix (or Group PTF) for the following
licensed products:
OS/400 release Product Group PTF
V4R3 5769-999 (SLIC) SF99066
V4R4 5769-SS1 (XPF) SF99067
V4R5 5769-JV1 (Java) SF99068
V5R1 SF99069
5769-999 (SLIC)
5769-SS1 (XPF)
5769-JV1 (Java)
5769-999 (SLIC)
5769-SS1 (XPF)
5769-JV1 (Java)
5722-999 (SLIC)
5722-SS1 (XPF)
5722-JV1 (Java)
For more information about using Management Central to simplify management of fixes, see Fixes.
10 iSeries: Getting started with Java on IBM iSeries: Using the IBM Developer Kit for Java
What you can do with Java
Java(TM) has the potential to connect users with information regardless of its source. Whether the data
comes from the Web, a database, an integrated file system, or any other entity, Java can control it. You
can create applications that run from almost anywhere, and still provide access to your server resources.
This list highlights only some of the many advantages Java has have to offer.
Internet applications
These Java applications and products are for use on the Internet:
v IBM WebSphere Application Server
Deploy and manage Java Web applications, ranging from simple Web sites to powerful e-business
solutions, with WebSphere Application Server.
v Servlets
Use servlets to enable e-business transaction processing.
v Secure connections
Ensure the safety of your system with secure connections.
v HTML classes
Create dynamic HTML with the IBM Toolbox for Java HMTL classes.
v Applets
Create animated graphics or interactive content for your Web page with applets.
applications
These Java applications are specific to IBM servers:
v
v IBM Developer Kit for Java
Create optimized Java code for specific OS/400 operations using the IBM Developer Kit for Java. The
following are some features of the IBM Developer Kit for Java:
–
– IBM Developer Kit for Java JDBC(TM) drivers
Create native database applications with the IBM Developer Kit for Java JDBC drivers.
– Abstract Window Toolkit (AWT)
Create GUIs with the Abstract Window Toolkit, which uses IBM Developer Kit for Java.
v IBM Toolbox for Java
Create client/server Java applications with the IBM Toolbox for Java. The following are some features of
the IBM Toolbox for Java:
–
– Program call
Use the ProgramCall class to call iSeries programs.
– Service program call
Use the ServiceProgramCall class to call iSeries service programs.
– Utility classes
Perform administrative tasks with IBM Toolbox for Java utility classes.
– IBM Toolbox for Java JDBC drivers
Create client/server database applications with the IBM Toolbox for Java JDBC drivers.
– Graphical Toolbox
Easily create graphical user interfaces (GUIs) with the Graphical Toolbox, a visual editing tool that
uses the IBM Toolbox for Java.
Setting up Java on iSeries 11
Java in general
These Java applications can be used on any compliant system:
v Java platform
Take advantage of these Java platform features:
–
– Applications
Access system resources with stand-alone applications.
– Java virtual machine
Use the Java Virtual Machine run time environment to run Java class files on any platform.
– Java class files
Create class files by compiling Java code.
– Java archive (JAR) files
Download Java applets with the cross-platform JAR format.
– Java interpreter
Interpret Java class files on any platform with the Java interpreter.
– Java threads
Perform multiple tasks at once with Java threads.
v Graphical user interface classes
Use the GUI classes to present data to and request data from users.
v Object-oriented programming
Enjoy the benefits of object-oriented programming with Java, such as code reuse, inheritance, and
abstraction.
v Java with other languages
Use Java to interact with code written in other languages, such as C++ and RPG.
v Garbage collection
Enjoy the convenience of garbage collection, which automatically frees storage by deleting unused
objects.
v Just-in-time (JIT) compilers
Code more efficiently with JIT compilers, which compile code as you need it.
IBM WebSphere Application Server overview
WebSphere Application Server works in conjunction with your Web server (such as IBM HTTP Server
for iSeries) to provide dynamic function in a Web site. WebSphere Application Server provides a run time
and application programming interfaces (APIs) for server-side Java components, which are based on Sun
Microsystems specifications.
v Servlets
Java servlets are typically used for business logic purposes. Servlets can access databases and
perform programmatic functions.
v JavaServer Pages(TM) (JSP) files
JSP files are typically used to present data. JSP tags are used in conjunction with HTML tags to
produce dynamic Web pages. For example, JSP tags can present variable data that is retrieved by a
servlet retrieves.
v Enterprise beans
Based on the Enterprise Java Beans(TM) specification, enterprise beans are used to model complex
data in a transaction-based environment. Entity beans can model part or all of a database. They also
synchronize with the database, changes to one are reflected in the other. Session beans model less
persistent data—a Web site shopping cart is a classic example of a session bean.
12 iSeries: Getting started with Java on IBM iSeries: Using the IBM Developer Kit for Java
You can use these Java components to build complex Web applications, such as an e-commerce Web
site.
WebSphere Application Server also includes APIs for manipulating Extensible Markup Language (XML)
documents. You can add these APIs to your server-side Java components to generate, validate, parse,
and present XML documents.
WebSphere Application Server includes utilities for administering the product. These utilities include a
Java-based administrative console, a Web-based console, a command-line interface, and a function that
allows you to import and export administrative data as XML documents.
Servlets
Servlets are Java applications that run on and interact with a Java-enabled Web server. Just as applets
run in a Java virtual machine in a browser, servlets run in a Java virtual machine in a Web server.
Servlets perform many of the same functions that common gateway interface (CGI) programs do.
However, because servlets can be pre-loaded by the Web server, servlets are usually faster than CGI
programs that perform the same functions. Servlets are also easier to write and maintain than CGIs, and
they are reusable across other server platforms.
The first step to getting started with servlets is to set up your Web server with a Java run time. To do this,
install a Java application server. See the IBM WebSphere site for more information .
For more information about servlets, see Servlets: The New 5250 Model . This IBM white paper gives
a comprehensive overview of servlets. Though it was written for v4r3 of OS/400, the vast majority of the
concepts discussed are still accurate. This white paper also lists sources where you can find more
information.
For a tutorial on servlets, see Introduction to Servlets and IBM WebSphere Application Server . This
free online tutorial teaches servlet programming with WebSphere Application Server for NT. Although it is
not geared toward the iSeries platform, the tutorial will teach you basic servlet programming concepts and
how to implement servlets with WebSphere Application Server.
Applets
An applet is a Java(TM) program designed to be included in an HTML Web document. The HTML
document contains tags, which specify the name of the Java applet and its uniform resource locator
(URL). The URL is the location at which the applet bytecodes reside on the Internet. When an HTML
document containing a Java applet tag is displayed, a Java-enabled Web browser downloads the Java
bytecodes from the Internet and uses the Java virtual machine to execute the code from within the Web
document. These Java applets are what enable Web pages to contain animated graphics or interactive
content.
For more information, see Writing Applets , Sun Microsystem’s tutorial for Java applets. It includes an
overview of applets, directions for writing applets, and some common applet problems.
The Java platform
The Javatm platform is the environment for developing and managing Java applets and applications. It
consists of three primary components: the Java language, the Java packages, and the Java virtual
machine. The Java language and packages are similar to C++ and its class libraries. The Java packages
contain classes, which are available in any compliant Java implementation. The application programming
interface (API) should be the same on any system that supports Java.
Setting up Java on iSeries 13
Java differs from a traditional language, like C++, in the way 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 figure 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 JAR files to
store class files. The class file does not target a specific hardware platform, but instead targets the Java
virtual machine architecture.
This figure shows the Java environment, as explained above.
You can embed the Java virtual machine within a Web browser or in an operating system such as IBM
Operating System/400 (OS/400). The Java virtual machine consists of the Java interpreter and run time.
The interpreter performs the task of interpreting the class file and running the Java instructions on a
particular hardware platform. The Java virtual machine is what allows Java code to be written and
compiled once, and run on any platform.
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.
Java applications
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 are restricted by the Java security model.
Java virtual machine
The Java virtual machine is a run time environment that you can add into a web browser or any
operating system, such as IBM Operating System/400 (OS/400). The Java virtual machine runs
instructions that a Java compiler generates. It consists of a bytecode interpreter and run time that allow
Java class files to run on any platform, regardless of the platform on which they were originally developed.
The class loader and security manager, which is part of the Java run time, insulate code that comes from
another platform. They also can restrict which system resources each class that is loaded accesses.
Note: Java applications are not restricted; only applets are restricted. Applications can freely access
system resources and use native methods. Most IBM 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 run time 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.
Note: The Java interpreter is only used if you specify OPTIMIZE(*INTERPRET) or INTERPRET(*YES).
14 iSeries: Getting started with Java on IBM iSeries: Using the IBM Developer Kit for Java
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.
Java class files
Java class files are stream files that are produced when a source file is compiled by the Java compiler.
The class file contains tables that describe each field and method of the class. The file also contains the
bytecodes for each method, static data, and descriptions that are used to represent Java objects.
Java JAR files
A Java ARchive (JAR) file is a file format that combines many files into one. You can use JAR as a
general archiving tool and also to distribute Java programs of all types, applets. Java applets download
into a browser in a single Hypertext Transfer Protocol (HTTP) transaction rather than by opening a new
connection for each piece. This method of downloading improves the speed at which an applet loads on a
Web page and begins functioning.
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.
To update classes in JAR files, see the Java ajar tool.
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 APIs.
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 nonblocking input and export with interrupts or multiple waits.
Threads allow the development of parallel programs that scale well in an environment where a machine
has multiple processors. If properly constructed, they also provide a model for handling multiple
transactions and users.
You can use threads in a Java program for a number of situations. Some programs must be able to
engage in multiple activities and still be able to respond to additional input from the user. For example, a
Web browser should be able to respond to user input while playing a sound.
Setting up Java on iSeries 15
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.
Java for e-business
Java is specially designed for e-business. IBM has optimized the OS/400 operating system to provide
excellent Java performance, especially when running the complex Java applications that are coming to
market. Working with these applications, Java and iSeries can help you establish an impressive Web
prescence. Understanding e-business concepts and products will enable you to use Java and iSeries to
their full potential.
Defining e-business
v What is e-business?
The Web site concisely explains the goals and strategies of e-business with the needs of an IBM
user in mind.
Solution scenario for e-business
v Road Map to iSeries Web Programming Technology
This guide will guide you through the process of building, maintaining, and improving your Web site. In
the road map, you will see the typical progression of a business-to-business site, from the simplest to
the most complex levels. At each level, the road map tells you the appropriate products and
technologies for accomplishing your Web programming goals.
Other information about Java
Now that you have sucessfully gotten started, you will likely want more information about Java topics.
There are many sources available to help you expand your knowledge.
v Java education
Learn the Java language better by using these educational resources.
v Java references
Get the answers to your Java questions here. This page contains a variety of sources to keep you
informed about the Java language and its features.
Java education
Continuing with your Java education does not have to be expensive. You can find several good Java
tutorials on the Internet, as well as other materials like books and articles. Listed below are some good
resources for learning about more Java programming.
IBM -specific Java education
Use these sources to find Java information tailored to your server:
16 iSeries: Getting started with Java on IBM iSeries: Using the IBM Developer Kit for Java
v PartnerWorld for Developers Java Education
This site features IBM -specific Java educational materials such as books, Internet-based
courses, classroom training, and workshops.
v NEWS/400’s Java Tutorial
This Web site contains a collection of articles written by Java and IBM server experts Phil Coulthard
and George Farr.
General Java education
Use these sources to find Java information applicable to all platforms:
v IBM Java Education
This site includes online courses, classroom training, white papers, tutorials, articles, books, and FAQs.
v The Java Tutorial
This Web site lists online Java tutorials (basic and advanced Java topics) available from Sun
Microsystems, Inc.
v Java Programming Language Basics, Part 1
This online tutorial walks through how to use the Java(TM) 2 Platform software to create and run three
common types of programs written for the Java platform—applications, applets, and servlets. (Sun
Microsystems, Inc.)
See Java and IBM references for other links that will be helpful in your Java education.
Java and IBM iSeries references
Use this list to find the information you need for working with Java on your server:
v IBM Redbooks
v Web sites
v Newsgroups
v Forums
IBM Redbooks
Select a link to see the abstract versions of a Redbook. After accessing the abstracts, you may view the
PDFs by selecting View online in the upper right of your screen. If this is your first visit to the IBM
Redbooks site, you will be required to complete a short registration form in order to view the PDFs. In
addition, you will need Adobe Acrobat Reader to access the PDF documents.
v Building AS/400 Internet-Based Applications with Java
This Redbook shows how to design and build iSeries Internet- or intranet-based Java applications,
applets, and servlets. If you are interested in the e-business capabilities of Java and iSeries, this
redbook is for you.
v Building Java Applications for the iSeries Server with VisualAge for Java 3.5
This Redbook explains how you can use Java and the IBM iSeries server to build server applications
and client/server applications.
Web sites
Visit these sites for more Web-based information about Java:
Setting up Java on iSeries 17
v iSeries Network
This site offers several good Java resources, including acces to the iSeries News online magazine,
forums, tutorials, articles on developing Java-based solutions, and more.
v
MCPressOnline
This site features a library of articles dedicated to the midrange market, forums, access to Midrange
Computing publications, a library of code samples, and more.
v iSeries for e-business home page
This site features information about managing an advanced e-business environment, including articles
on e-business infrastructure, business-to-business solutions, case studies, and more.
v IBM Toolbox for Java and JTOpen home page
This site contains all sorts of information about IBM Toolbox for Java, including evaluation downloads,
troubleshooting, and frequently-asked questions.
v Java for iSeries PartnerWorld for Development page
The most comprehensive site dedicated to Java and iSeries, this home page features articles,
demonstrations, solutions, resources, and information about ″real world″ Java implementations by
iSeries business partners.
v developerWorks: Java Technology Zone
This is IBM’s main Java site, offering developer tools and assistance, technology previews, Java
tutorials and education, feature articles, and JCentral, a search engine tuned to Java on the Internet.
v WebSphere software platform home page
This site features information about WebSphere, the only e-business platform that can provide
everything you need to build, deploy and integrate your e-business.
v VisualAge for Java home page
This site provides information about VisualAge for Java, an integrated development environment (IDE)
that offers proven support for building and testing Java applets, servlets, and Enterprise JavaBeans
components.
Newsgroups
Join a newsgroup for up-to-the-minute Java information:
v iSeries newsgroup
v Java technology newsgroups at developerWorks
Forums
Visit a forum for new information from other users:
v developerWorks Java technology forums
v MCPressOnline discussion forums
v iSeries Network discussion forums
18 iSeries: Getting started with Java on IBM iSeries: Using the IBM Developer Kit for Java
Getting started with Java Feedback
What do you think of Getting started with Java? We welcome your comments and suggestions!
What is your name?
What is your e-mail address?
Enter your comments below:
Other ways to send us feedback:
You can send comments by fax using one of these numbers:
United States and Canada: 1-800-937-3430 Other countries: 1-507-253-5192
You can mail us at:
IBM Corporation
Attention Department XTN
IDCLERK
3605 Highway 52N
Rochester, MN 55901-7829 USA
Note: Please contact your IBM representative if you need specific marketing or service help or if you have
specific comments about the functions of IBM products or systems.
The fine print:
By choosing to send a message to IBM, you acknowledge that all information contained in your message,
including feedback data, such as questions, comments, suggestions, or the like, shall be deemed to be
non-confidential and IBM shall have no obligation of any kind with respect to such information and shall be
free to reproduce, use, disclose, and distribute the information to others without limitation. Further, IBM
shall be free to use any ideas, concepts, know-how or techniques contained in such information for any
purpose whatsoever, including, but not limited to, developing, manufacturing and marketing products
incorporating such information.
Setting up Java on iSeries 19
20 iSeries: Getting started with Java on IBM iSeries: Using the IBM Developer Kit for Java
Printed in U.S.A.