Eight years of age but going on about 35, Java has quickly entrenched itself in far-flung areas: peer-to-peer, open source, wireless, and embedded applications, to name just a few. It’s easy to lose track of where the language is going, because it’s headed everywhere at once.
For this series, I asked veteran Java developers to talk about trends they perceive as important. The first installment covered the Java Community Process and its bureaucratic issues. Now, we’re going to look at the increasing incidence of scripting languages in the Java realm and the pluses and minuses of using them.
It’s all about rapid development
No question about it: Scripting languages, such as Jython, Python, Perl, and PHP, are becoming more and more popular. Jython is actually a complete implementation of the Python programming language. It’s written in 100 percent pure Java and allows easy access to Java libraries.
This scripting trend is being driven largely by rapid application development (RAD), a development style that is gaining disciples all the time. As marketing executives put the full-court press on IT shops to speed production, IT managers are forced to look at the most efficient ways to beat deadlines. RAD is a prime mover here.
“You can be very clever with some scripting languages and do things you can’t do with regular Java,” said Mukund Balasubramanian, CTO of Redwood City, CA-based Infravio, a Java and Web services integrator. “If you know how to use a good scripting language, you can save a lot of time and money in development.”
The advantages of scripting languages
Balasubramanian said that scripting languages offer the following advantages:
- Rapid development: They shorten the “develop, deploy, test, debug” cycle greatly.
- Ease of deployment: Most offer drop-in deployment with no time-intensive compile/package cycles.
- Integration with existing technologies: They are built around component technologies like Java or COM to leverage the code.
- Easy to learn and use: Skills required are usually lower and easier to find in large numbers.
- Dynamic code: Scripting language code can be generated and executed at runtime, an advanced feature useful and necessary in some applications (e.g., dynamic types in JavaScript).
The disadvantages of scripting languages
However, Java scripting languages do have a few disadvantages:
- They are not comprehensive. They assume the presence of a “real” programming language; for example, you’d be hard-pressed to find a database driver built into a scripting language.
- They are not conducive to best practices in software engineering and code structuring, such as object orientation and component-based development.
- They are usually not “general purpose” but tuned toward a specific application, such as PHP and the World Wide Web.
“Thus, scripting languages can quicken the pace of software development to a very large extent, but must be carefully chosen for a specific application—such as dynamic Web pages or to complement a ‘real’ programming language like Jython to Java,” Balasubramanian said.
Third-party utilities help mesh scripts with basic framework
Utilities such as IBM’s Bean Scripting Framework make hooking Tcl, Python, Perl, and other scripting languages into a Java application fairly easy. Sun, Borland, BEA, and others also offer these utilities. But longtime Java developer David Kearns of Mentor Graphics in Wilsonville, OR, pointed out that there are time and cost risks with supporting a single scripting language, let alone a half-dozen of them.
In a recent article he wrote for Java World, Kearns described the risks inherent in supporting a scripting language in your Java application.
“Jython has the fastest scripting interpreters I looked at and has some powerful programming features,” he said. “My only real concern was about Jython’s control-flow syntax, which might or might not be important to you. As with Jacl, writing scripts for Jython may have more of a learning curve to it than JavaScript or BeanShell do, since there is more new ground to cover. If you want to write nontrivial scripts in Python, I recommend buying a book. Python is a popular programming language, so you’ll have plenty to choose from at the bookstore.”
Other Java scripting languages
Here’s a rundown of the most widely used Java-oriented scripting languages, courtesy of Java guru William Wagers of About.com:
Beanshell
BeanShell is a small, free, downloadable, embeddable Java source-code interpreter with object-scripting language features that’s written in Java. BeanShell executes standard Java statements and expressions, in addition to obvious scripting commands and syntax. It supports scripted objects as simple method closures like those in Perl and JavaScript.
Jess
Jess is a rule engine and scripting environment written entirely in the Java language. Jess was originally inspired by the CLIPS expert system shell but has grown into a complete, distinct, dynamic environment of its own. Using Jess, you can build Java applets and applications that have the capacity to “reason” using knowledge you supply in the form of declarative rules.
JudoScript
JudoScript is a Java-type script that features HTTP client and server programming, file system and archiving, XML and XSLT scripting, JDBC scripting, and HTML scraping. It also sports a scheduler with monitor, sendmail, run executables, Java GUI creation, FTP, SSH and SCP, Windows registry, etc. Software download, including source, is free.
Rhino
Rhino is an open source implementation of JavaScript written purely in Java. It is typically embedded into Java applications to provide scripting to end users.
Is scripting the future of Java?
Do you think that scripting is planted firmly in Java’s future? Post your comments below or e-mail us.