Java and RPG Definitions and Data Types

The data types of the parameters and the returned value of the method are specified in the same way as they are when prototyping a subprocedure, but the data types actually map to Java™ data types. The following table shows the mappings of ILE RPG data types to and from Java data types.

If you copy the JNI member in QSYSINC/QRPGLESRC, you can use LIKE to define your RPG variables and parameters like definitions in that file. For example, to define a variable like the Java "int" type, define it LIKE(jint). In the remainder of the discussion about RPG and Java, any definitions defined with LIKE(jxxxx) are assumed to have a /COPY for QSYSINC/QRPGLESRC,JNI in the module. See the section Additional RPG Coding for Using Java for more information about using this /COPY file.

Table 1. RPG definitions for Java data types
Java Data Type ILE RPG Data Type RPG Definitions
boolean indicator N
byte 1 integer 3I 0
character 1A
byte[] character length > 1 (See 3.) nA
array of character length=1 (See 4.) 1A DIM(x)
date D
time T
timestamp Z
short 2–byte integer 5I 0
char UCS-2 length=1 1C
char[] UCS-2 length>1 (See 3.) nC
array of UCS-2 length=1 (See 4.) 1C DIM(x)
int 4–byte integer 10I 0
long 8–byte integer 20I 0
float 4–byte float 4F
double 8–byte float 8F
any object object O CLASS(x)
any array array of equivalent type (See 4.) DIM(x)
Note:
  1. When a Java byte type is converted to or from a character (1A) data type, ASCII conversion occurs. When a Java byte type is converted to or from an integer (3I) data type, ASCII conversion does not occur.
  2. For arrays of any type in Java, you can declare an array of the equivalent type in RPG. However, note that you cannot use an array of character length greater than 1 or UCS-2 length greater than 1 data types.
  3. For UCS-2 length greater than 1 and character length greater than 1 data types, the VARYING keyword is allowed. In general, it's recommended to use the VARYING keyword, since Java byte[] and char[] cannot be declared with a fixed length.
  4. For RPG array data types, OPTIONS(*VARSIZE) should normally be coded for array parameters, since Java arrays cannot be declared with a fixed length.

Zoned, Packed, Binary, and Unsigned data types are not available in Java. If you pass a Zoned, Packed, Binary, or Unsigned field as a parameter, the compiler will do the appropriate conversion, but this may result in truncation and/or loss of precision.

When calling a method, the compiler will accept arrays as parameters only if the parameter is prototyped using the DIM keyword.

If the return value or a parameter of a method is an object, you must provide the class of the object by coding the CLASS keyword on the prototype. The class name specified will be that of the object being returned or the parameter being passed. (Use the EXTPROC keyword to specify the class of the method being called.)

If the method being called is a static method, then you must specify the STATIC keyword on the prototype. If the method is a constructor, you must specify *CONSTRUCTOR as the name of the method.

In Java, the following data types can only be passed by value:
boolean
byte
int
short
long
float
double

Parameters of these types must have the VALUE keyword specified for them on the prototype.

Note that objects can only be passed by reference. The VALUE keyword cannot be specified with type O. Since arrays are seen by Java as objects, parameters mapping to arrays must also be passed by reference. This includes character and byte arrays. The CONST keyword can be used.