Java 6 introduces scripting engine support in to Java, and this new support provides a link between the Java and delayed binding world of scripting languages.
This all is possible with a simple package that java provides us. The Java Scripting functionality is in the
javax.script package. This is a relatively small, simple API. Scripts can be executed from within java in the JVM. Many independent scripting packages have been available for Java for some time, including Rhino, Jacl, Jython, BeanShell, JRuby, and others. To work with scripts, you only need to know a couple of key classes, form which here we will learn two of them:
The ScriptEngine interface models script engines, and the ScriptEngineManager class provides convenient methods to register and obtain a ScriptEngine object.
To instantiate a script engine, you use the
ScriptEngineManagerclass to retrieve a
Generally it handles two key functions:
i. Discovery of script engine
ii. Storing data in context
It provides a key value pair, which is provided to all the instances of ScriptEngine created by the
ScriptEngineManager and it is referred as “Global state”.
The output of the program will be:
For more information on scripting packages, its variables, API and various examples to work with you can visit Java Scripting guide.
So if you find a problem like mine and hopefully you come across this article, I would be grateful helping you with your queries🙂