GetJavaClass function

Syntax

GetJavaClass(ClassName)

Description

Use the GetJavaClass function to access a Java class so that you can manipulate it in PeopleCode. This is used for those classes that have static members, where it isn't appropriate to instantiate an object of the class. You can call only static methods, that is, class methods, with the object created with this function.

In Java, you access such static members of a class by using the class name:

result = java.class.name.SomeStaticMethod();

To do this in PeopleCode, do the following:

&Result = GetJavaClass("java.class.name").SomeStaticMethod();

Note:

If you create a class that you want to call using GetJavaClass, it can be located in a directory specified in the PS_CLASSPATH environment variable or in other specified locations. The PeopleCode API Reference provides details on where you can place custom and third-party Java classes.

See PeopleCode API Reference: System Setup for Java Classes.

Parameters

Parameter Description

ClassName

Specify the name of an already existing class. This parameter takes a string value.

Returns

A JavaObject that refers to the named Java class.

Example

The Java class java.lang.reflect.Array has no public constructors and has only static methods. The methods are used to manipulate Java array objects. One of these static methods is GetInt:

public static int getInt(Object array, int index)

To use this method, get the class by using GetJavaClass. This code illustrates accessing the value of the fifth element of an integer array.

Local JavaObject &RefArray, &MyArray;
. . .
&RefArray = GetJavaClass("java.lang.reflect.Array");
. . .
&MyArray = CreateJavaArray(“int[]”, 24);
. . .
&FifthElement = &RefArray.getInt(&MyArray, 4);