Wednesday, August 04, 2010

scripting language di java

wah gw baru tau nih, ternyata  bisa gini ya

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

public class ScriptDemo {

    public static void main(String[] args) {
       
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("js");
       
        try {
            String expression = "3+4";
            Object result = engine.eval(expression);
            System.out.println(expression+" = "+result);
        } catch(ScriptException se) {
            se.printStackTrace();
        }
    }
}

No comments:

Post a Comment