Run Java snippets through the code interpreter Java kernel.
The standard code-interpreter template includes a Java Jupyter kernel.
result = machine.run_code("""int total = 0;for (int value : new int[] {1, 2, 3}) { total += value;}total""", language="java")print(result.results[0].text)
const result = await machine.code.run(`int total = 0;for (int value : new int[] {1, 2, 3}) { total += value;}total`, { language: "java" });console.log(result.results[0].text);
nullspace machine code run mch_123 "int total = 0;for (int value : new int[] {1, 2, 3}) { total += value;}total" --language java
# returns a Server-Sent Events stream of JSON eventscurl -N -X POST "${NULLSPACE_API_URL}/v1/machines/mch_123/code/execute" \ -H "Authorization: Bearer ${NULLSPACE_API_KEY}" \ -H "Content-Type: application/json" \ -d '{"code": "int total = 0;\nfor (int value : new int[] {1, 2, 3}) {\n total += value;\n}\ntotal", "language": "java"}'
Use Java contexts for snippets that should share definitions across executions.