Apr 15

Java introduced scripting support with Java 6.

Heres a simple example showing how to use the JavaScript scripting engine to evaluate an expression.

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
Object result = engine.eval("6 * (3 + 5)");

written by objects \\ tags: , , , ,


2 Responses to “Evaluate expression”

  1. Shuja Says:

    Hi
    i was using in the same way and my expression is some thing like that 1/11. I was expecting 0.090 as result but it is returning 1. So the question is how to return value in decimal?

    Thanks
    Shuja

  2. objects Says:

    Try 1.0 / 11.0

Leave a Reply

You must be logged in to post a comment.