Home » Core Java » script » Get script engine’s details

About 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 at Java Code Geeks.

Get script engine’s details

In this example we shall show you how to get the ScriptEngine‘s details. The ScriptEngine 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. The ScriptEngineManager 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.
  • Use getEngineFactories() API method to get a list whose elements are instances of all the ScriptEngineFactory classes found by the discovery mechanism.
  • For every ScriptEngineFactory use getEngineName() method to get the full name of the ScriptEngine.
  • Use getEngineVersion() method to get the version of the ScriptEngine.
  • Use getLanguageName() method to get the name of the scripting langauge supported by this ScriptEngine.
  • Use getLanguageVersion() method to get the version of the scripting language supported by this ScriptEngine.
  • Use getExtensions() method to get an immutable list of filename extensions, which generally identify scripts written in the language supported by this ScriptEngine.
  • Use getNames() 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.

(No Ratings Yet)
Start the discussion Views Tweet it!

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

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 ....

 

Receive Java & Developer job alerts in your Area

 

Leave a Reply

avatar
  Subscribe  
Notify of