Package javax.script


packagejavax.script

The scripting API consists of interfaces and classes that defineJava Scripting Engines and providesa framework for their use in Java applications. This API is intendedfor use by application programmers who wish to execute programswritten in scripting languages in their Java applications. Thescripting language programs are usually provided by the end-users ofthe applications.

The main areas of functionality ofjavax.scriptpackage include

  1. Script execution: Scriptsare streams of characters used as sources for programs executed byscript engines. Script execution useseval methods ofScriptEngine and methods of theInvocable interface.

  2. Binding: This facilityallows Java objects to be exposed to script programs as namedvariables.Bindings andScriptContextclasses are used for this purpose.

  3. Compilation: Thisfunctionality allows the intermediate code generated by thefront-end of a script engine to be stored and executed repeatedly.This benefits applications that execute the same script multipletimes. These applications can gain efficiency since the engines'front-ends only need to execute once per script rather than once perscript execution. Note that this functionality is optional andscript engines may choose not to implement it. Callers need to checkfor availability of theCompilableinterface using aninstanceof check.

  4. Invocation: Thisfunctionality allows the reuse of intermediate code generated by ascript engine's front-end. Whereas Compilation allows entire scriptsrepresented by intermediate code to be re-executed, Invocationfunctionality allows individual procedures/methods in the scripts tobe re-executed. As in the case with compilation, not all scriptengines are required to provide this facility. Caller has to checkforInvocable availability.

  5. Script engine discovery: Applicationswritten to the Scripting API might have specific requirements onscript engines. Some may require a specific scripting languageand/or version while others may require a specific implementationengine and/or version. Script engines are packaged in a specifiedway so that engines can be discovered at runtime and queried forattributes. The Engine discovery mechanism is based on the service-providerloading facility described in theServiceLoader class.ScriptEngineManagerincludesgetEngineFactories method to get allScriptEngineFactory instancesdiscovered using this mechanism.ScriptEngineFactory hasmethods to query attributes about script engine.

Since:
1.6
  • Class
    Description
    Provides a standard implementation for several of the variants of theeval method.
    A mapping of key/value pairs, all of whose keys areStrings.
    The optional interface implemented by ScriptEngines whose methods compile scripts to a form that can be executed repeatedly without recompilation.
    Extended by classes that store results of compilations.
    The optional interface implemented by ScriptEngines whose methods allow the invocation of procedures in scripts that have previously been executed.
    The interface whose implementing classes are used to connect Script Engines with objects, such as scoped Bindings, in hosting applications.
    ScriptEngine is the fundamental interface whose methods must be fully functional in every implementation of this specification.
    ScriptEngineFactory is used to describe and instantiateScriptEngines.
    TheScriptEngineManager implements a discovery and instantiation mechanism forScriptEngine classes and also maintains a collection of key/value pairs storing state shared by all engines created by the Manager.
    The genericException class for the Scripting APIs.
    A simple implementation of Bindings backed by aHashMap or some other specifiedMap.
    Simple implementation of ScriptContext.