Java Reference
In-Depth Information
toDisplay) that you can use to find the syntax for printing text on the standard output.
The following snippet of code shows how to get the syntax for Nashorn:
// Get the script engine factory for Nashorn
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
ScriptEngineFactory factory = engine.getFactory();
// Get the script
String script = factory.getOutputStatement("\"Hello JavaScript\"");
System.out.println("Syntax: " + script);
// Evaluate the script
engine.eval(script);
Syntax: print("Hello JavaScript")
Hello JavaScript
For other scripting languages, use their engine factories to get the syntax.
Exploring the javax.script Package
The Java Scripting API in Java consists of a small number of classes and interfaces. They
are in the javax.script package. This chapter contains a brief description of classes and
interfaces in this package. I will discuss their usage in subsequent chapters. Figure 1-1
shows the class diagram for the classes and interfaces in the Java Scripting API.
Figure 1-1. The class diagram for classes and interfaces in the Java Scripting API
The ScriptEngine and ScriptEngineFactory Interfaces
The ScriptEngine interface is the main interface of the Java Scripting API whose
instances facilitate the execution of scripts written in a particular scripting language.
 
Search WWH ::




Custom Search