Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which scripting language interpreters does JDK contain?

Tags:

java

jvm

Some time ago I read about JavaTM Scripting API, but I could not find information about which language-interpreters (excepting JS) Oracle JVM implements. Where can I find a full list? Or does the JVM not interpret anything but JavaScript by default?

ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript"); // what else?
like image 960
bsiamionau Avatar asked Oct 05 '22 18:10

bsiamionau


2 Answers

I'm guessing you know most of what I'm about to say, but lest someone else stumble upon this who doesn't:

Javascript is included by default, as it was the reference implementation (Rhino). It's not quite right to consider it "embedded" - the implementation just happens to be bundled as a reference implementation for JSR-223. As far as I'm aware, it's no different than any other implementation, except that it happens to exist by default.

However, implementations exist for MANY other languages, aren't JVM/JDK specific (just requiring Java 6 or better) and are fairly trivial to add in an application.

I've used Perl, Groovy, Haskell, Javascript, and Python and a few others (doing some performance testing, related to possibly using it as a solution).

There are a lot of available languages if you want to install them: https://confluence.deri.ie:8443/display/romulus/JSR+223+compliant+scripting+languages

like image 98
James Avatar answered Oct 10 '22 02:10

James


I found answer with @Jesper assistance. javax.script.ScriptEngineManager has method getEngineFactories() which returns...

...a list whose elements are instances of all the ScriptEngineFactory classes found by the discovery mechanism.

I wrote this code snippet to get list of supported engines:

ScriptEngineManager factory = new ScriptEngineManager();
for (ScriptEngineFactory sef : factory.getEngineFactories()) {
    System.out.println(sef.getEngineName() + " (" + sef.getLanguageName() + ")");
}

Output:

Mozilla Rhino (ECMAScript)

Rhino is an open-source implementation of JavaScript written entirely in Java.

Conclusion:

Oracle JDK has only one embedded script-language interpreter - JS interpreter.

like image 39
bsiamionau Avatar answered Oct 10 '22 03:10

bsiamionau