The scripting API consists of interfaces and classes that define Java™ Scripting Engines and provides a framework for their use in Java applications. This API is intended for use by application programmers who wish to execute programs written in scripting languages in their Java applications. The scripting language programs are usually provided by the end-users of the applications.
The main areas of functionality of
javax.script package include
Script execution : Scripts are streams of characters used as sources for programs executed by script engines. Script execution uses
ScriptEngineand methods of the
Compilation: This functionality allows the intermediate code generated by the front-end of a script engine to be stored and executed repeatedly. This benefits applications that execute the same script multiple times. These applications can gain efficiency since the engines' front-ends only need to execute once per script rather than once per script execution. Note that this functionality is optional and script engines may choose not to implement it. Callers need to check for availability of the
Compilableinterface using an instanceof check.
Invocation: This functionality allows the reuse of intermediate code generated by a script engine's front-end. Whereas Compilation allows entire scripts represented by intermediate code to be re-executed, Invocation functionality allows individual procedures/methods in the scripts to be re-executed. As in the case with compilation, not all script engines are required to provide this facility. Caller has to check for
Script engine discovery : Applications written to the Scripting API might have specific requirements on script engines. Some may require a specific scripting language and/or version while others may require a specific implementation engine and/or version. Script engines are packaged in a specified way so that engines can be discovered at runtime and queried for attributes. The Engine discovery mechanism is based on the service-provider loading facility described in the
getEngineFactoriesmethod to get all
ScriptEngineFactoryinstances discovered using this mechanism.
ScriptEngineFactoryhas methods to query attributes about script engine.
Interface Summary Interface Description BindingsA mapping of key/value pairs, all of whose keys are
CompilableThe optional interface implemented by ScriptEngines whose methods compile scripts to a form that can be executed repeatedly without recompilation. InvocableThe optional interface implemented by ScriptEngines whose methods allow the invocation of procedures in scripts that have previously been executed. ScriptContextThe interface whose implementing classes are used to connect Script Engines with objects, such as scoped Bindings, in hosting applications. ScriptEngine
ScriptEngineis the fundamental interface whose methods must be fully functional in every implementation of this specification.
ScriptEngineFactoryis used to describe and instantiate
Class Summary Class Description AbstractScriptEngineProvides a standard implementation for several of the variants of the
CompiledScriptExtended by classes that store results of compilations. ScriptEngineManagerThe
ScriptEngineManagerimplements a discovery and instantiation mechanism for
ScriptEngineclasses and also maintains a collection of key/value pairs storing state shared by all engines created by the Manager.
SimpleBindingsA simple implementation of Bindings backed by a
HashMapor some other specified
SimpleScriptContextSimple implementation of ScriptContext.
Exception Summary Exception Description ScriptExceptionThe generic
Exceptionclass for the Scripting APIs.