Taming Mustang, Part 2: Scripting API Tour
Editor's Note: This article was originally published on Feb 23, 2007. It was updated on November 2, 2007.
Last time, I introduced a three-part series that explores new Java Standard Edition 6 features not covered in my Start Saddling Up for Mustang article for JavaWorld, and my Mustang (Java SE 6) Gallops into Town InformIT article. Part 1 explored enhancements to the Collections API.
Here in Part 2 you'll take a tour of Mustang's new Scripting API, which lets you create programs that are part Java and part scripting language. This hybrid "Java/scripting language" approach to developing software benefits from Java's wealth of APIs and its other advantages, and from scripting language advantages such as support for dynamic typing.
Tour the Scripting API
JSR 223: Scripting for the Java Platform is the Java Specification Request (JSR) under which the Scripting API was created. This JSR's goal is to "describe mechanisms allowing scripting language programs to access information developed in the Java Platform and allowing scripting language pages to be used in Java Server-side Applications."
Although early versions of JSR 223 introduced the Web Scripting Framework (which was assigned to package javax.scripting.http) for generating Web content in servlet containers, this framework became optional as the specification evolved. Because the Web Scripting Framework is not included in Mustang, it is not discussed in this article.
The Scripting API is associated with package javax.script. This package identifies six classes and six interfaces. You will be introduced to each class and interface as you read this article.
- AbstractScriptEngine
- Bindings
- Compilable
- CompiledScript
- Invocable
- ScriptContext
- ScriptEngine
- ScriptEngineFactory
- ScriptEngineManager
- ScriptException
- SimpleBindings
- SimpleScriptContext
In addition to javax.script, Mustang introduces a single script engine (a plug-in that evaluates a scripting language's scripts by executing their intermediate code). This script engine evaluates JavaScript scripts and is based on Mozilla Rhino version 1.6R2. Mozilla's Rhino: JavaScript for Java page provides more information on Mozilla Rhino.