ScriptEngine: eval(String script) : ScriptEngine « javax.script « Java by API






ScriptEngine: eval(String script)

  
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class Main {

  public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("js");
    String script = "print ('www.java2s.com')";
    try {
      engine.eval(script);
    } catch (ScriptException e) {
      e.printStackTrace();
    }
  }
}

   
    
  








Related examples in the same category

1.ScriptEngine: eval(Reader reader)
2.ScriptEngine: getBindings(int scope)
3.ScriptEngine: get(String key)
4.ScriptEngine: put(String key, Object value)