script

Get script engine’s details

Photo of Byron KiourtzoglouByron KiourtzoglouNovember 11th, 2012Last Updated: October 2nd, 2013
0 84 1 minute read

In this example we shall show you how to get theScriptEngine‘s details. TheScriptEngine interface provides methods for basic scripting functionality. Applications written to this simple interface are expected to work with minimal modifications in every implementation. It includes methods that execute scripts, and ones that set and get values. To get the ScriptEngine’s details one should perform the following steps:

  • Create a new ScriptEngineManager. TheScriptEngineManager implements a discovery and instantiation mechanism for ScriptEngine classes and also maintains a collection of key/value pairs storing state shared by all engines created by the Manager.
  • UsegetEngineFactories() API method to get a list whose elements are instances of all theScriptEngineFactory classes found by the discovery mechanism.
  • For every ScriptEngineFactory usegetEngineName() method to get the full name of the ScriptEngine.
  • UsegetEngineVersion() method to get the version of the ScriptEngine.
  • UsegetLanguageName() method to get the name of the scripting langauge supported by this ScriptEngine.
  • UsegetLanguageVersion() method to get the version of the scripting language supported by this ScriptEngine.
  • UsegetExtensions() method to get an immutable list of filename extensions, which generally identify scripts written in the language supported by this ScriptEngine.
  • UsegetNames() method to get an immutable list of short names for the ScriptEngine, which may be used to identify the ScriptEngine by the ScriptEngineManager,

as described in the code snippet below.

package com.javacodegeeks.snippets.core;import javax.script.ScriptEngineManager;import javax.script.ScriptEngineFactory;import java.util.List;public class GetScriptEngine {    public static void main(String[] args) {    // Get new instance of script engine  ScriptEngineManager manager = new ScriptEngineManager();  List<ScriptEngineFactory> factories = manager.getEngineFactories();  // Print details  for (ScriptEngineFactory factory : factories) {System.out.println(  "EngineName= " + factory.getEngineName());System.out.println(  "EngineVersion   = " + factory.getEngineVersion());System.out.println(  "LanguageName    = " + factory.getLanguageName());System.out.println(  "LanguageVersion = " + factory.getLanguageVersion());System.out.println(  "Extensions= " + factory.getExtensions());List<String> names = factory.getNames();for (String name : names) {    System.out.println("Engine Alias = " + name);}  }    }}

Output:

EngineName = Mozilla Rhino EngineVersion = 1.7 release 3 PRERELEASE LanguageName = ECMAScript LanguageVersion = 1.8 Extensions =  Engine Alias = js Engine Alias = rhino Engine Alias = JavaScript Engine Alias = javascript Engine Alias = ECMAScript Engine Alias = ecmascript

 
This was an example of how to get the ScriptEngine’s details in Java.

Do you want to know how to develop your skillset to become aJava Rockstar?
Subscribe to our newsletter to start Rockingright now!
To get you started we give you our best selling eBooks forFREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to theTerms andPrivacy Policy

Thank you!

We will contact you soon.

Photo of Byron KiourtzoglouByron KiourtzoglouNovember 11th, 2012Last Updated: October 2nd, 2013
0 84 1 minute read
Photo of Byron Kiourtzoglou

Byron Kiourtzoglou

Byron is a master software engineer working in the IT and Telecom domains. He is an applications developer in a wide variety of applications/services. He is currently acting as the team leader and technical architect for a proprietary service creation and integration platform for both the IT and Telecom industries in addition to a in-house big data real-time analytics solution. He is always fascinated by SOA, middleware services and mobile development. Byron is co-founder and Executive Editor atJava Code Geeks.

Related Articles

Bipartite Graph

Get script engine by name

November 11th, 2012
Bipartite Graph

Import package in script

November 11th, 2012
Bipartite Graph

Modify Java object in script

November 11th, 2012
Bipartite Graph

Evaluate a simple script

November 11th, 2012
Bipartite Graph

Evaluate a script file

November 11th, 2012
Subscribe
Notify of
guest
I agree to theTerms andPrivacy Policy
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.

I agree to theTerms andPrivacy Policy
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.