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

Write the Java Main Method

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

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

Figure 31. Java Sample Program #3 - Passing an Integer
 // Read an integer, call PL/I, display new integer upon return
 import java.io.*;
 import java.lang.*;

 public class jPassInt{

  /* Fields to hold Java string and int                  */
  int myInt;
  String myString;

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

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

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

    System.out.println(" ");

    /* Instantiate Java class and initilize string       */
    jPassInt pInt = new jPassInt();
    pInt.myInt = 1024;
    pInt.myString = " ";

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

         /* Process until 'quit' received                */
         while (!pInt.myString.equalsIgnoreCase("quit")) {
           System.out.println
             ("From Java: Enter an Integer or 'quit' to quit.");
           System.out.print("Java Prompt > ");
           /* Get string from command line               */
           pInt.myString = in.readLine();
           if (!pInt.myString.equalsIgnoreCase("quit"))
             {
              /* Set int to integer value of String      */
              pInt.myInt = Integer.parseInt( pInt.myString );
              /* Call PL/I native method                 */
              pInt.pliShowInt();
              /* Return from PL/I and display new string */
              System.out.println(" ");
              System.out.println
                ("From Java: Integer set by PL/I is: " + pInt.myInt );
             }
         }
         }  catch (IOException e) {
         }
  }

 }

Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)