Static Java Method Calls

Static methods can be invoked just like any other method using the JavaCallMethod function. Since static methods are defined on a Java class and not on a Java object, the constant JAVA_STATIC_METHOD must be used in place of a handle to a Java object, for example hTestObj. The second parameter defining the method name now begins with the fully qualified class name, where the method is defined, then a '.' symbol, and then the method name. A fully qualified class name means that the package that contains the class must also be specified. Use the '/' symbol as a separator between subpackages.

JavaCallMethod(JAVA_STATIC_METHOD, "test/mypackage/Test.doFoo") calls the static doFoo method of the Test class in the mypackage subpackage in the package test.

Like member methods, static methods may also expect and return parameters. To define an input parameter for a static method, use the following function calls prior to invoking the test method:

The datatype of the first parameter of the static Java test method must match the first usage of the JavaSetParameter function, and so on. In parameters are only valid for the following static method call.

To call a static Java method that returns a parameter, use the following function calls after invoking the test method:

Here is an example of a parameterized static Java method call:

dcltrans
  transaction TMyStaticJavaTrans
  var
    fValue : float;
  begin                            
    ThinkTime(0.2);
    // set the first parameter
    JavaSetString(JAVA_STATIC_METHOD, "1");
    // set the second parameter
    JavaSetNumber(JAVA_STATIC_METHOD, 1, JAVA_BYTE);
    // invoke the method
    JavaCallMethod(JAVA_STATIC_METHOD, "test/mypackage/Test.doFoo");
    // retrieve the result
    fValue := JavaGetFloat(JAVA_STATIC_METHOD);
    Print("doFoo returned "+String(fValue));
  end TMyStaticJavaTrans;

Additional Samples

<public user documents>\Silk Performer 20.0\Samples\JavaFramework\JavaFrameworkSample.bdf

<public user documents>\Silk Performer 20.0\Samples\JavaFramework\JavaFrameworkSample.java