home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / documentation / tutorial / native1.1 / implementing / example-1.1 / MyTest.java < prev    next >
Encoding:
Text File  |  1997-07-13  |  1.9 KB  |  69 lines

  1. /*
  2.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "copyright.html"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  */
  17. class MyTest {
  18.     /*public native int getline(StringBuffer s, int len);*/
  19.     // members
  20.     int myInt = 1;
  21.     double myDbl = 1.1;
  22.     float myFlt;
  23.     String myString;
  24.  
  25.     /* constructor */
  26.     public MyTest(){
  27.         System.out.println("In constructor function");
  28.     }
  29.  
  30.     public native int getLine(String s, int len);
  31.     public native int getChar(StringBuffer sb);
  32. //    public native int[] getIntValue(int[] arr);
  33.     public native int getIntValue(int[] arr, double[] darr);
  34.  
  35.   // string method(s)
  36.   public native int createString(String s, int len);
  37.  
  38.     // create an array
  39.     public native int[] createArray(int[] arr);
  40.  
  41.     // get information
  42.     public native int getInfo();
  43.     // test error handling
  44.     public native int handleError2() throws IllegalArgumentException;
  45.     public native int handleError(int ivalue);
  46.  
  47.     // java methods
  48.     public void displayHello() {
  49.        System.out.println("Hello World! ");
  50.     }
  51.  
  52.     public int doCalc(int i, int n) {
  53.         int j;
  54.         System.out.println("Start of doCalc; i= " + i);
  55.         if (i==0) {
  56.            i = n;
  57.         }
  58.         for (j=1;j<5;j++) {
  59.            i = i + j;
  60.         }
  61.         System.out.println("Ready to exit doCalc; i= " + i);
  62.         return(i);
  63.     }
  64.  
  65.     static {
  66.         System.loadLibrary("mytest");
  67.     }
  68. }
  69.