A bit different this one.
I was recently asked by a fellow IBM Champion to give him a quick run through on Java on the IBM i, so I thought I would write a quick article on this topic for others out there.
Installation of Java
Java has to be installed on our IBM i server before we can do anything Java related.
The first step is to install the Java licensed program, for Version 7.3 of the IBM i OS this is 5770JV1, where we need the *BASE with options 16 (32-bit version), and 17 (64-bit version).
This can be seen in the figure below.
We can see here, I have both the 32-bit and 64-bit versions installed.
To complete the installation, we need to install the latest Java group PTFs. For my version of IBM i (7.3), this is SF99725, which is shown in the screen shot below.
We now have Java installed on our server and can start using it.
The first step to take is to set an environment variable to tell Java which version we want to use.
The command below, shows the settings required to use the 64-bit version.
ADDENVVAR ENVVAR(JAVA_HOME) VALUE(‘/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit’) LEVEL(*JOB)
To use the 32-bit version, the environment variable would be as follows.
ADDENVVAR ENVVAR(JAVA_HOME) VALUE(‘/QOpenSys/QIBM/ProdData/JavaVM/jdk80/32bit’) LEVEL(*JOB)
IBM recommends you do not set the JAVA_HOME environment variable to be the *SYSTEM level, as this may negatively affect applications already setting their own versions to run in.
If you wish to specify the version in a shell session, for your job, we can use the export JAVA_HOME variable to use whichever version you require.
The example below shows me using the 64-bit version..
export JAVA_HOME=/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit
This will set the JAVA_HOME variable to affect only jobs using this shell session. If you wish this to always apply to a users session, it is advised you use a shell session profile for the user.
To check which version of Java you are using, use a shell session and run.
JAVA -VERSION
The screen shot of my server shows we are running the 64-bit version.
What Java versions are your jobs running?
To check which version of Java your jobs are running, use the Work with JVM Job command (WRKJVMJOB).
From this screen, take an option 5 to display the JVM job you need to know about.
The screen shot below shows our schools REST service using the 64-bit version of the JDK toolkit.
Java Programs
In this section we will write a very simple Java program and run it.
First thing to note about Java programs, is that they are compiled. Java is not an interpreted language like many other languages, PHP, Node.JS etc.
Let me copy a Hello World example into our IFS.
Back into our shell, we can see our source and compile it.
- Our java source file
- Compile our source using the JAVAC command
- We now have the compiled object called Hello.class
- We call our Java compiled program (be aware of case!)
- Shows the output from our java program
Support
You will be pleased to know that the Java Development Kit is included in your Software Maintenance Agreement (SWMA) with IBM if you are on Version 7.3 or Version 7.4 of the OS.
If you are hitting any problems, open a PMR.
Conclusion
Hopefully, this article has given you a quick insight into the Java world on the IBM i.
I will be giving a one-day workshop on everything Node.js and Open Source at the next i-UG user group meeting in July 2021 in the UK. Hopefully, we can all meet up again and get back to normal, government restrictions permitting.
If you have any questions, either on this article, or anything else open source, use the comments below, or send me a message on twitter @AndyYouens
Andy Youens is an IBM i consultant/instructor at Milton Keynes, UK-based FormaServe Systems with over 40 years IBM midrange experience.
IBM Champion 2021
Leave a Reply