Java Reference
In-Depth Information
Because R treats all numbers as floating point, like many interpreters, the value printed is
84.0
.
You can also find out the installed scripting engines and pick one that is on your classpath.
simple script in the default language, ECMAScript (aka JavaScript).
Example 24-7. ScriptEnginesDemo.java
public
public class
class
ScriptEnginesDemo
ScriptEnginesDemo
{
public
public static
throws
ScriptException
{
ScriptEngineManager scriptEngineManager
=
new
static
void
void
main
(
String
[]
args
)
throws
new
ScriptEngineManager
();
// Print list of supported languages
scriptEngineManager
.
getEngineFactories
().
forEach
(
factory
->
System
.
out
.
println
(
factory
.
getLanguageName
()));
// Run a script in the JavaScript language
String lang
=
"ECMAScript"
;
ScriptEngine engine
=
scriptEngineManager
.
getEngineByName
(
lang
);
iif
(
engine
==
null
null
) {
System
.
err
.
println
(
"Could not find engine"
);
return
return
;
}
engine
.
eval
(
"print(\"Hello from "
+
lang
+
"\");"
);
}
}
See Also
To see the full list of languages, and download the “script engines”—the interfaces from Java
to each of the languages—visit the
Oracle page
or the
java.net
page
.
At present, the website is borked; to view the list of engines at
Java.net
you have to save the
file and open it manually; the web server dishes it with the wrong content type.