Wed, Jul
0 New Articles

Display Java System Attributes from Within RPG

  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Turn conceptual Java properties into definitive, concrete attributes.


When working with RPG in different environments, such as production and test, you will most likely be working with different library lists and using different versions of programs and files. To provide a sanity check for yourself, you will want to ensure that you're using the correct programs and files by validating the objects that are being used by the job. This article shows you some methods that I use to verify similar Java attributes when using Java with RPG, such as the currently running version of JVM and the class path that is being used.


I recently had the opportunity to work with some very talented and innovative RPG and Java programmers in North Carolina who were working together to implement the programming methodologies that are presented in my book Advanced Integrated RPG, which covers various ways to implement open-source Java functionality within RPG programs. During my visit, we discussed some issues relating to working with Java within RPG, which also matched some topics that are actively being discussed in the forums. This article attempts to clarify some of these topics.

Checking the Java Virtual Machine (JVM) Version in Qshell

One quick and easy way to see which version of Java is being used is to execute Java from the Qshell command line (just as you would from a Windows DOS or Linux command prompt) by passing in the "-version" parameter.


You can enter Qshell by typing strqsh. At the Qshell command line, you then enter "java -version" to see something similar to the following (your results may vary, depending upon the version you're running on your system):



Figure 1: Determine which version of Java you're using. (Click images to enlarge.)

Identifying Multiple JVMs

For the purpose of identifying that a JVM exists on your IBM i and determining, which version it is, using Qshell does the job. But what if you have multiple JVMs on your machine?


You can see which JVMs are installed on your IBM i by using the go licpgm command. When you display the licensed programs on your system, you can find all of the Java Development Kits (JDKs) that are installed (your list may look different, depending upon what is installed on your system):


Figure 2: Determine which licensed programs you have installed.


You may assume that the latest Java version is the one being used, but that's not always the case. You could check the version of Java in Qshell, but that's a different environment. How do you know that is the same one that is being used by RPG? And if you do have multiple JVM versions on your system and you're attempting to override one to use another one that is not the default, how do you know that the settings you've applied are actually being used? The best way would be to simply ask the JVM.

Java System Properties

Java has a System class that has various facilities that include access to the properties of the JVM and environment variables. To access the current properties, you can use the getProperty method, along with a string parameter identifying the property that you are interested in.


One of the many packages included with the JVM is the java.lang package. Contained in that package is the System class. The System class has a few methods that you can use to retrieve the properties. Figure 3 shows a partial JavaDoc listing of the System property methods. (Note: You can find the complete online JavaDocs for the System class by clicking here.)


Figure 3: This is a partial listing of the System property methods.


The list of available properties are contained within the JavaDocs for the System class and can be found by clicking here. Here is a partial list to demonstrate some useful properties that you may be interested in:


Useful Properties




Java Runtime Environment version


Java Runtime Environment vendor


Java installation directory


Java class path


Operating system name


Operating system architecture


Operating system version


User's account name


User's home directory


User's current working directory


The two methods I have displayed above, getProperties and getProperty, will return the same values in different ways. To stay focused on the objective, we will use the getProperty method, which allows us to specify a single property that we are interested in and returns a string that we can work with. If you were to use the getProperties method, you would receive all of the properties in a Properties object.


To enable RPG to access the Java method, we will create a prototype to access the getProperty method of the java.lang.System class, as follows:


D System_getProperty...

D                 PR                  like(jString)

D                                     ExtProc(*JAVA

D                                     :'java.lang.System'

D                                     :'getProperty')

D                                     static

D   argString                         like(jString)


If you refer to the JavaDocs above, you will see that the getProperty method will accept a String object as the parameter and will also return a String object. You can also see in the JavaDocs that the method is static, so we will need to specify that on the prototype.


Because we are working with RPG, which uses EBCDIC, we will need to handle the conversions to ASCII for the JVM to be able to understand the bytes of data we're sending. For this situation, I like to put an RPG wrapper around the call to the prototyped Java method that will handle the character conversions. This way, I can code it once and make it as painless as possible for future reuse, as follows:



P* Air_getSystemProperty(): Gets the System.getProperty


P Air_getSystemProperty...

P                 B                   EXPORT

D Air_getSystemProperty...

D                 PI         65535A   varying

D  argBytes                  65535A   const varying options(*varsize)

D svString        S                   like(jString)

D svResult        S                   like(jString)

D svBytes         S          65535A   varying


  svString = new_String(%trim(argBytes));

  svResult = System_getProperty(svString);

  svBytes = String_getBytes(svResult);

  return svBytes;


P                 E


Here is what the procedure is doing:

  1. The incoming EBCDIC bytes are converted into ASCII when the String object is constructed with the call to new_String.
  2. Then, the resulting String object is passed as the parameter to the System_getProperty prototype for the Java method, which will return ASCII bytes.
  3. Finally, the ASCII byte results are converted to EBCDIC for use in RPG.


The Character set conversions can be a pain, which is why I like to wrap them up into procedures. Plus, doing so gives you the modular design to enhance your procedure later on to possibly add exception handling.

The Code

With the prototype defined, we can now write some code to use this new method. I wrote an article called "Advanced Integrated RPG: Using Java with RPG" that covers some of the details on how to use the Java String Object within RPG and how to start and stop the JVM. So I'll reuse that code in our example.


When using the getProperty method, all you have to do is pass in the string to indicate the system property that you're interested in. So, for our example, we will get the version of Java that is currently being used by RPG, the class path, the operating system name, the operating system version, and the user name. And because we wrapped our Java calls inside of a procedure that handles our character conversions, we can simply pass in our strings as straight text in our code:



       // Call getJNIEnv() to:

       // - Ensure First Three File Descriptors are open

       // - Start JVM, if not started

       // - Attach to JVM, if already started


       // Java Version

       displayBytes = 'Java Version: '

                    + Air_getSystemProperty('java.version');

       DSPLY displayBytes;

       // Java Class Path

       displayBytes = 'Java ClassPath: '

                    + Air_getSystemProperty('java.class.path');

       DSPLY displayBytes;

       // Operating System Name

       displayBytes = 'Operating System Name: '

                    + Air_getSystemProperty('os.name');

       DSPLY displayBytes;

       // Operating System Version

       displayBytes = 'Operating System Version: '

                    + Air_getSystemProperty('os.version');

       DSPLY displayBytes;

       // User Name

       displayBytes = 'User Name: '

                    + Air_getSystemProperty('user.name');

       DSPLY displayBytes;

       *inlr = *ON;


Running the program would generate results similar to the following:



Figure 4: Show the system properties.


You can see that RPG is using Java Version 1.4.2 on OS/400 V5R3M0 (your results may vary, based on the system you're running on). Now you know exactly which version of the JVM is being used within your RPG code on your system.

Static Note

I want to point out something about static methods that could be especially helpful to anyone who is new to Java and has been trying this out with RPG. You may have noticed that I did not need to create an instance of the System class in order to access its methods. This is because it is a static method of the class. This means that you do not need to create an instance because the state/value of the method applies to all instances of the class and is not dependent upon an instance to be created; all you have to do is call the method and you will get the value you're looking for.


If you look on the left side of the JavaDocs, you will see the static keyword specified. When you create the prototype for the method, you need to indicate that it is static.

Adding Java to Your RPG Toolbox

As Joe Pluta pointed out in one of his recent articles, "Choosing a Web Language? Choose Wisely," Android is now a viable option in the mobile computing market, and it's my latest avenue of programming exploration as well. This now gives Java more relevance when you're deciding which Web language to use on your IBM i. Think about it: you could really integrate Java with RPG, run Java right on your IBM i without any dependence upon an outside server, and also use the very same language to write your mobile applications. You might want to add that to your pros versus cons list when you are making your decision.

Download the Code

For the intentions of providing an autonomous working example, I have placed all of the prototypes and procedures into the same code source. But, for modular coding reuse, I recommend putting the procedures into a separate file to be copied into the source. And I would create a service program with the procedures. You can download the code by clicking here.


At this point, I do not encourage the use of fixed-formatted programming and would not want to convolute the service programs, so I did not provide the procedure in fixed-format. But, for the purpose of accessing the service programs from existing fixed-formatted programs, I did provide an example of accessing the procedures with some fixed-formatted code.


Thomas Snyder

Thomas Snyder has a diverse spectrum of programming experience encompassing IBM technologies, open source, Apple, and Microsoft and using these technologies with applications on the server, on the web, or on mobile devices.

Tom has more than 20 years' experience as a software developer in various environments, primarily in RPG, Java, C#, and PHP. He holds certifications in Java from Sun and PHP from Zend. Prior to software development, Tom worked as a hardware engineer at Intel. He is a proud United States Naval Veteran Submariner who served aboard the USS Whale SSN638 submarine.

Tom is the bestselling author of Advanced, Integrated RPG, which covers the latest programming techniques for RPG ILE and Java to use open-source technologies. His latest book, co-written with Vedish Shah, is Extract, Transform, and Load with SQL Server Integration Services.

Originally from and currently residing in Scranton, Pennsylvania, Tom is currently involved in a mobile application startup company, JoltRabbit LLC.

MC Press books written by Thomas Snyder available now on the MC Press Bookstore.

Advanced, Integrated RPG Advanced, Integrated RPG
See how to take advantage of the latest technologies from within existing RPG applications.
List Price $79.95

Now On Sale

Extract, Transform, and Load with SQL Server Integration Services Extract, Transform, and Load with SQL Server Integration Services
Learn how to implement Microsoft’s SQL Server Integration Services for business applications.
List Price $79.95

Now On Sale



Support MC Press Online


Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: