O'Reilly logo

Scripting in Java: Integrating with Groovy and JavaScript by Kishori Sharan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 2

image

Executing Scripts

In this chapter, you will learn:

  • How to use the eval() method of ScriptEngine to execute scripts
  • How to pass parameters from Java code to Nashorn engine
  • How to pass parameters from Nashorn engine to Java

Using the eval() Method

A ScriptEngine can execute a script in a String and a Reader. Using a Reader, you can execute a script stored on the network or in a file. One of the following versions of the eval() method of the ScriptEngine interface is used to execute a script:

  • Object eval(String script)
  • Object eval(Reader reader)
  • Object eval(String script, Bindings bindings)
  • Object eval(Reader reader, Bindings bindings) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required