V8 | Java Addon
This is where V8 shines over Nashorn. You can push Java objects into the JS context and call JS functions from Java.
compiledScriptId = runtime.createScript(script); runtime.executeScript(compiledScriptId); Java Addon V8
public class OptimizedV8Usage private V8 runtime; // Reuse compiled scripts private int compiledScriptId; This is where V8 shines over Nashorn
+-------------------------------------------------------+ | JVM Process | | +-------------------------------------------------+ | | | Java Code | | | +-------------------------------------------------+ | | | | | Java Native Interface | | | | | +-------------------------------------------------+ | | | C++ Bridge (JNI) | | | +-------------------------------------------------+ | | | | | +-------------------------------------------------+ | | | V8 Engine Core | | | | (Isolates, Contexts, Heap Memory) | | | +-------------------------------------------------+ | +-------------------------------------------------------+ Key Concepts in V8 Addons public class OptimizedV8Usage private V8 runtime
v8.registerJavaMethod(new V8JavaCallback() @Override public Object invoke(V8Object receiver, V8Array parameters) String name = parameters.getString(0); return "Welcome, " + name;
Optimized for low-end devices while keeping the Java aesthetic.