- Latest (GraalVM for JDK 21)
- Dev Build
- GraalVM for JDK 21
- GraalVM for JDK 20
- GraalVM for JDK 17
- GraalVM 22.3
- GraalVM 22.2
- GraalVM 22.1
- GraalVM 22.0
- GraalVM 21.3
- Java on Truffle
- Node.js Runtime
- Java Interoperability
- Differences Between Node.js and Java Embeddings
- ScriptEngine Implementation
- LLVM Languages Reference
- Python Reference
- Ruby Reference
- R Reference
- WebAssembly Reference
Differences Between Node.js and Java Embeddings
For example, Node.js applications executed using GraalVM’s
bin/node executable have access to all of Node.js’ APIs, including built-in Node.js modules such as
Context Creation #
In a Java application, a new context can be created using the
New contexts can be configured in multiple ways, and configuration options include exposing access to Java classes, allowing access to IO, etc.
A list of context creation options can be found in the API documentation.
In a Node.js application, the GraalVM
Context executing the application is pre-initialized by the Node.js runtime, and cannot be configured by the user application.
In this scenario, Java classes can be exposed to the Node.js application by using the
--vm.cp= command line option of the
bin/node command, as described below.
Java Interoperability #
Java built-in object.
The object is not available by default, and can be enabled in the following way:
- In Node.js mode, start GraalVM using the
- In Java, create a GraalVM context using the
- In Node.js mode, multiple contexts can be created using Node.js’ Worker threads API. The Worker threads API ensures that no sharing can happen between two parallel contexts.
- In Java, multiple contexts can be executed from multiple threads. As long as a context is not accessed by two threads at the same time, parallel execution happens safely.
Java Libraries #
Java built-in object.
In order for a Java library to be accessible from a
jar files need to be added to the GraalVM classpath. This can be done in the following way:
- In Node.js mode, the classpath can be modified using the
- In Java, the default Java’s
-cpoption can be used.
More details on GraalVM command line options are available in Options.
npm package registry can be used from Node.js as well as from Java:
'http', etc.) Modules can be loaded using a package bundler, or using the available built-in mechanisms for ES modules. CommonJS modules are supported in Java mode under an experimental flag.