//polyglot programmer /
same way after coding in Python, where
whitespace is syntactically significant.
The stereotype of the lone-wolf programmer locked away in a room has
faded in recent years. Team software
development is the norm, and pair programming is an accepted Agile practice.
Communities with different strengths
grow up around a language. With such considerations in mind, developers
might want to set up an
environment where they
can test-drive several
new languages to quickly
compare them. Java—
specifically the Java Virtual
Machine (JVM)—provides
an excellent platform for
such an exercise.
with each recent Java release. JSR-223
defined a scripting interface that was
completed in Java SE 6. In Java SE 7,
JSR-292 provides additional benefits
including improved performance and
additional support for dynamically
typed languages. The JVM is mature,
widely deployed, and heavily opti-
mized, and it includes
excellent tools and allows
access to a large variety
of libraries.
The output from each of these
commands should indicate a Java
SDK version of 1. 6. If it does not,
download and install a Java SDK
(the Microsoft Windows version is
jdk1.6.0_ 14).
2. Download and install Maven, and
make sure it is included in your PATH
environment variable. Then run the
following command:
Note: You can also run the file
by using the Java interpreter and
referencing the JAR itself. The jvms
.bat script contains such a call for a
Microsoft Windows environment,
and the jvms.sh script contains
such a call for a Mac OS environment. The remainder of this article
uses “mvn” to avoid operating-system-specific details.
6. To compare various languages, pass
at the command line the scripts that
are to be evaluated.
One or more files can be passed
as arguments, and the files can
use the same or different scripting languages. The scripts used
in this article reside in src\main\
resources\scripts. The customary
“Hello World” example can be run
as follows:
COMMUNITY
JAVA IN ACTION
The Apache Maven
project presented
here can be set up in
minutes and allows
developers to run
and compare scripts
written in five dynamic
scripting languages:
Clojure, Groovy,
JavaScript, JRuby,
and Jython.
mvn -version
Java and the JVM
The Java language is not—
and was never intended
to be—the perfect programming language for
every situation. The JVM
is software constructed to
execute bytecode compiled from Java. Each JVM implementation is designed to run on a specific
platform. The original vision was to
allow Java to be compiled once and run
on a variety of platforms. But the JVM
has also been leveraged in recent years
to run bytecode created by other programming languages.
The JVM has accommodated other
languages for some time, and support
for such languages has been improved
Start Your Engines
Trying out Clojure, Groovy,
JavaScript, JRuby, and
Jython requires an initial
setup in order to find,
download, install, and
configure each imple-
mentation. The project
described here reduces
the time and effort
required by using Maven
to locate and download
resources from various
public code repositories.
Maven is also used to
build the project so
that a single executable JAR is created,
which contains a class that can be used
to run scripts written in several differ-
ent languages.
Setup
To run the project, do the following:
1. Validate your Java installation by
running the following commands:
The output of this command
should indicate that a recent version
of Maven is installed (for example,
version 3.0.3).
mvn -q exec:java -Dexec.args=
" hello.clj hello.js hello.groovy
hello.rb hello.py"
ABOUT US
mvn clean install
All downloaded JAR files are
installed in your local Maven reposi-
tory (by default, in your home direc-
tory under .m2/repository).
blog
javac -fullversion
java -fullversion
mvn -q exec:java
Additional Scripts
In addition to the “hello” scripts, several
other scripts (described in a bit more
detail below) are provided that can get
you started with your own experiments.
You can run these scripts and modify
them to compare and contrast Clojure,
Groovy, JavaScript, Python, and Ruby. In
some cases, the code is nearly identical,
but in other cases, it is radically different. When you run a set of scripts, you
will also notice that the output shows a
time in nanoseconds for each script. This
allows you to create scripts in several