Sobes.tech
Middle

What is jjs?

sobes.tech AI

Answer from AI

jjs is a command-line utility in the Java Development Kit (JDK) designed for executing JavaScript code. It is part of the Nashorn JavaScript engine, which was integrated into Oracle JDK 8 and removed in JDK 15.

Main features:

  • Executing JavaScript files: You can run a .js file by passing it as an argument to jjs.
  • Interactive mode: Running jjs without arguments opens an interactive shell (REPL), where you can input and execute JavaScript commands directly.
  • Interaction with Java: Nashorn allowed calling Java classes and objects from JavaScript and vice versa, enabling JavaScript to script Java applications.
// Example of using jjs to execute a script
// file my_script.js
print("Hello from jjs!");
jjs my_script.js
# Interactive mode jjs
jjs
jjs> print("Enter interactive mode");
jjs> var x = 10;
jjs> print(x * 2);

In later versions of JDK (starting from JDK 15), Nashorn and consequently jjs were removed in favor of integrating with other JavaScript engines via JEP 372. Therefore, the relevance of jjs depends on the JDK version used.