Recipe 26.6 Calling Java from Native Code


Problem

You need to go the other way, calling Java from C/C++ code.

Solution

Use JNI again.

Discussion

Starting from 1.1, JNI provides an interface for calling Java from C, with calls to:

  1. Create a JVM

  2. Load a class

  3. Find and call a method from that class (e.g., main)

JNI lets you add Java to legacy code. That can be useful for a variety of purposes and lets you treat Java code as an extension language (just define or find an interface or class like Applet or Servlet, and let your customers implement it or subclass it).



Java Cookbook
Java Cookbook, Second Edition
ISBN: 0596007019
EAN: 2147483647
Year: 2003
Pages: 409
Authors: Ian F Darwin

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net