> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ns.rocks/llms.txt
> Use this file to discover all available pages before exploring further.

# Java

> Run Java snippets through the code interpreter Java kernel.

The standard `code-interpreter` template includes a Java Jupyter kernel.

<CodeGroup>
  ```python Python SDK theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  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)
  ```

  ```typescript TypeScript SDK theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  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);
  ```

  ```bash CLI theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  nullspace machine code run mch_123 "int total = 0;
  for (int value : new int[] {1, 2, 3}) {
      total += value;
  }
  total" --language java
  ```

  ```bash HTTP API theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  # returns a Server-Sent Events stream of JSON events
  curl -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"}'
  ```
</CodeGroup>

Use Java contexts for snippets that should share definitions across executions.

## Related

* [Supported languages](./languages-overview)
* [Code contexts](./contexts)
