Chapter 24. Using Java with Other Languages
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 Running an External Program from Java.
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 Calling Other Languages via javax.script.
Or you can drop down to C level with Java’s “native code” mechanism and call compiled functions written in C/C++; see Calling Other Languages via Native Code.
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 16), with HTTP services (see Chapter 16), or with Java clients in RMI or CORBA clients in a variety of languages.
There is a wide range of other JVM languages, including:
- 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 Automating Dependencies, Compilation, Testing, and Deployment with Gradle).
- Jython, a full Java ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access