Scripting in Java Tutorial - Scripting in Java Scope

A scope works with a Bindings.

The scope of a Bindings determines the visibility of its key-value pairs.

One Bindings occurs only in one scope.

The script engine searches the a variable name in the Bindings with a higher precedence first, then search Bindings with lower precedence.

The Java Scripting API defines two scopes.

  • ScriptContext.ENGINE_SCOPE
  • ScriptContext.GLOBAL_SCOPE

The engine scope has higher precedence than the global scope.