Java Reference
In-Depth Information
knownst to the user, and the Perl part and the Java bits communicate through a TCP socket
(see
Chapter 16
).
Marrying two platform-independent languages, like Perl and Java, in a portable way skirts
many portability problems. When distributing inlined applications, be sure to supply not just
the source files but also the contents of the
_Inline
directory. (It is advisable to purge that dir-
ectory and to rebuild everything just before distribution time; otherwise, old compiled ver-
sions left lying around might make it into the distribution.) Each target machine needs to re-
peat the magic steps of
Inline::Java
, which requires a Java compiler. In any case, the
In-
line::Java
module must be installed.
Because Perl has
Inline
modules for a number of other languages (ordinary languages like
C, but others as exotic as Befunge), one might even consider using Perl as glue for interoper-
ation between those other languages, jointly or separately, and Java. I am sure many happy
hours can be spent working out the intricacies of such interactions.
See Also
mentation) that is installed along with the module itself.
Calling Other Languages via Native Code
Problem
You wish to call native C/C++ functions from Java, either for efficiency or to access hard-
ware- or system-specific features.
Solution
Use JNI, the Java Native Interface.
Discussion
Java lets you load native or compiled code into your Java program. Why would you want to
do such a thing? The best reason would probably be to access OS-dependent functionality, or
existing code written in another language. A less good reason would be speed: native code