Chapter 18. Using Java with Other Languages
18.0 Introduction
Java has several methods of running programs written in other languages. You can invoke a compiled program or executable script using Runtime.exec()
, as I’ll describe in Recipe 18.1.
There is an element of system dependency here, because you can only run external applications
under the operating system they are compiled for.
Alternatively, you can invoke one of a number of scripting languages (or dynamic languages)—running the gamut: awk, bsh, Clojure, Ruby, Perl, Python, Scala—using javax.script
, as illustrated in Recipe 18.3.
Or you can drop down to C level with Java’s native code mechanism and call compiled functions written in C/C++; see Recipe 18.6.
From native code, you can call to functions written in just about any language. Not to mention that you can contact programs written in any language over a socket (see Chapter 13), with HTTP services (see Chapter 13), or with Java clients in RMI or CORBA clients in a variety of languages.
There is a wide range of other JVM languages, including these:
-
BeanShell, a general scripting language for Java.
-
Groovy is a Java-based scripting language that pioneered the use of closures in the Java language ecosystem. It also has a rapid-development web package called Grails and a build tool called Gradle (see Recipe 1.8). Gradle is also used as the build tool in modern Android development.
-
Jython, a full Java implementation of Python.
-
JRuby, a full Java implementation ...
Get Java Cookbook, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.