Rational Developer for System z
PL/I for Windows, Version 8.0, Programming Guide

Write the Java Main Method

The jPassString class also includes a main method to instantiate the class and call the native method. The main method instantiates jPassString and calls the pliShowString() native method.

This sample program prompts the user for a string and reads that value in from the command line. This is done within a try/catch statement as shown in Figure 30.

Figure 30. Java Sample Program #2 - Passing a String
 // Read a string, call PL/I, display new string upon return
 import java.io.*;

 public class jPassString{

  /* Field to hold Java string                           */
  String myString;

  /* Load the PL/I native library                        */
  static {
          System.loadLibrary("passString");
  }

  /* Declare the PL/I native method                      */
  public native void pliShowString();

  /* Main Java class                                     */
  public static void main(String[] arg) {

    System.out.println(" ");

    /* Instantiate Java class and initilize string       */
    jPassString myPassString = new jPassString();
    myPassString.myString = " ";

    /* Prompt user for a string                          */
    try {
         BufferedReader in = new BufferedReader(
           new InputStreamReader(System.in));

         /* Process until 'quit' received                */
         while (!myPassString.myString.equalsIgnoreCase("quit")) {
           System.out.println(
             "From Java: Enter a string or 'quit' to quit.");
           System.out.print("Java Prompt > ");
           /* Get string from command line               */
           myPassString.myString = in.readLine();
           if (!myPassString.myString.equalsIgnoreCase("quit"))
             {
              /* Call PL/I native method                 */
              myPassString.pliShowString();
              /* Return from PL/I and display new string */
              System.out.println(" ");
              System.out.println(
                  "From Java: String set by PL/I is: "
                + myPassString.myString );
             }
         }
         }  catch (IOException e) {
         }
  }
 }
Rational Developer for System z
PL/I for Windows, Version 8.0, Programming Guide