|  package 
                      javatech.jni22;
 /** Demonstrates array handling. **/
 public class ArrayExample
 {
 // Load the native library.
 static { System.loadLibrary ("NativeArray"); 
                      }
 
 // Declare the native methods.
 public native float nativeProcessArray (float[] 
                      array, int elem);
 public native int nativeProcessArrayRegion (int[] 
                      array);
 public native void nativeModifyArrayRegion (int[] 
                      array);
 public native void nativeProcess2DArray (int[][] 
                      array);
 
 /** Constructs an ArrayExample object which 
                      makes calls into the
 * native code. **/
 public ArrayExample () {
 
 // Call the nativeProcessArray method 
                      to extract the 7th element from
 // and array of floats and to modify 
                      the 3rd element.
 float[] array = { 0.f, 1.f, 2.f, 
                      3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f };
 System.out.println ("Calling nativeProcessArray");
 float element7 = nativeProcessArray 
                      (array, 7);
 System.out.println ("7th array element 
                      is " + element7);
 System.out.println ("modified array 
                      element 3 is " + array[3]);
 
 // Call nativeProcessArrayRegion() 
                      to sum elements 5 to 15 of
 // the long int array.
 int[] very_long = new int[1000];
 for (int i=0; i < very_long.length; 
                      i++)
 very_long[i] = i;
 System.out.println ("\nCalling nativeProcessArrayRegion");
 int sum = nativeProcessArrayRegion 
                      (very_long);
 System.out.println ("sum from native 
                      method = " + sum);
 
 // Call nativeModifyArrayRegion() 
                      to modify elements 5 to 15.
 // Print out just the first 20 elements 
                      to see what got modified.
 System.out.println ("\nCalling nativeModifyArrayRegion");
 nativeModifyArrayRegion (very_long);
 for (int i=0; i < 20; i++)
 System.out.println ("very_long["+i+"] 
                      = " + very_long[i]);
 
 // Call nativePRocess2DArray.
 int[][] i2d = new int[2][4]; // 
                      an array of 2 arrays of int[4]
 System.out.println ("\nlength of 
                      i2d  is " + i2d.length);
 System.out.println ("length of i2d[0] 
                      is " + i2d[0].length);
 System.out.println ("length of i2d[1] 
                      is " + i2d[1].length);
 for (int i=0; i < 2; i++)
 for (int j=0; j<4; j++)
 i2d[i][j] 
                      = 1000*(i+1) + (j+1);
 System.out.println ("original values:");
 for (int i=0; i<2; i++)
 for (int j=0; j < 4; 
                      j++)
 System.out.println 
                      ("i2d["+i+"]["+j+"] = " + i2d[i][j]);
 nativeProcess2DArray (i2d);
 System.out.println ("modified values:");
 for (int i=0; i < 2; i++)
 for (int j=0; j < 4; 
                      j++)
 System.out.println 
                      ("i2d["+i+"]["+j+"] = " + i2d[i][j]);
 } // ctor
 
 /** Starts the demo running. **/
 public static void main (String[] args) {
 new ArrayExample ();
 } // main
 
 } // ArrayExample
 |