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:

Get Java Cookbook, 3rd 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.