CompilableDemo.java Source code

Java tutorial

Introduction

Here is the source code for CompilableDemo.java

Source

import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class CompilableDemo {

    public static void main(String[] args) throws Exception {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("js");

        Compilable jsCompile = (Compilable) engine;
        CompiledScript script = jsCompile.compile("function hi () {print ('www.java2s.com !'); }; hi ();");

        for (int i = 0; i < 5; i++) {
            script.eval();
        }
    }
}
//www.java2s.com !www.java2s.com !www.java2s.com !www.java2s.com !www.java2s.com !