Source of UseObjects.java


  1: //: appendixb:UseObjects.java
  2: // From 'Thinking in Java, 2nd ed.' by Bruce Eckel
  3: // www.BruceEckel.com. See copyright notice in CopyRight.txt.
  4: class MyJavaClass {
  5:   public int aValue;
  6:   public void divByTwo() { aValue /= 2; }
  7: }

  9: public class UseObjects {
 10:   private native void 
 11:     changeObject(MyJavaClass obj);
 12:   static {
 13:     System.loadLibrary("UseObjImpl");
 14:     // Linux hack, if you can't get your library
 15:     // path set in your environment:
 16:     // System.load(
 17:     //"/home/bruce/tij2/appendixb/UseObjImpl.so");
 18:   }
 19:   public static void main(String[] args) {
 20:     UseObjects app = new UseObjects();
 21:     MyJavaClass anObj = new MyJavaClass();
 22:     anObj.aValue = 2;
 23:     app.changeObject(anObj);
 24:     System.out.println("Java: " + anObj.aValue);
 25:   }
 26: } ///:~