Nashorn JavaScript engine
suggest changeVersions
Java SE 8.
Introduction
Nashorn is a JavaScript engine developed in Java by Oracle and released with Java 8. It was removed in Java 15. Nashorn allows embedding JavaScript in Java applications via JSR-223 and allows you to develop standalone JavaScript applications. It provides better runtime performance and better compliance with the ECMAScript specification than the engine it replaced.
Syntax
- ScriptEngineManager // Provides a discovery and installation mechanism for ScriptEngine classes; uses a SPI (Service Provider Interface)
- ScriptEngineManager.ScriptEngineManager() // Recommended constructor
- ScriptEngine // Provides the interface to the scripting language
- ScriptEngine ScriptEngineManager.getEngineByName(String shortName) // Factory method for the given implementation
- Object ScriptEngine.eval(String script) // Executes the specified script
- Object ScriptEngine.eval(Reader reader) // Loads and then executes a script from the specified source
- ScriptContext ScriptEngine.getContext() // Returns the default bindings, readers and writers provider
- void ScriptContext.setWriter(Writer writer) // Sets the destination to send script output to
Remarks
Nashorn is a JavaScript engine written in Java and included in Java 8. You use it through the javax.script package.
Note that the ScriptEngineManager provides a generic API allowing you to obtain script engines for various scripting languages (i.e. not only Nashorn, not only JavaScript).
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents