Java

Run Java 21 online

Compile and execute Java code instantly in a secure, isolated sandbox. No JDK setup, no installs. Just write and run.

code.java
Output
Click "Run Code" to execute...

About Java

Java is the enterprise standard for building robust, cross-platform applications. With the JVM ecosystem, strong typing, and decades of battle-tested libraries, Java powers everything from Android apps to large-scale distributed systems.

Our sandbox runs Java 21 (LTS) with full JDK support.

Sandbox features

  • Secure execution with Docker + gVisor isolation
  • Java 21 LTS with full JDK
  • Sync/stream: Basic 30s, Pro 60s, Ultra/Mega 150s; async: Ultra 300s, Mega 600s
  • Stdin support for interactive programs
  • REST API for programmatic access
  • No setup or installation required

Use Java with stateful sessions

Open a session once, then call execute repeatedly. Files written under /home/sandbox persist between calls; each call starts a fresh process, so variables do not carry over. Package install is available for Python (pip) and JavaScript/TypeScript (npm) sessions only.

# 1. Create a session (PRO, ULTRA, or MEGA)
curl -X POST https://sandboxapi.p.rapidapi.com/v1/sessions \
  -H "X-RapidAPI-Key: $RAPIDAPI_KEY" \
  -H "X-RapidAPI-Host: sandboxapi.p.rapidapi.com" \
  -H "Content-Type: application/json" \
  -d '{"language":"java","idle_ttl":300}'
# → {"id":"sess_abc","language":"java",...}

# 2. Write a file in the session
curl -X POST https://sandboxapi.p.rapidapi.com/v1/sessions/sess_abc/execute \
  -H "X-RapidAPI-Key: $RAPIDAPI_KEY" \
  -H "X-RapidAPI-Host: sandboxapi.p.rapidapi.com" \
  -H "Content-Type: application/json" \
  -d '{"code":"public class Main{public static void main(String[] a)throws Exception{java.nio.file.Files.writeString(java.nio.file.Path.of(\"/home/sandbox/state.txt\"),\"42\");}}"}'

# 3. A later call reads it back: files persist, variables do not
curl -X POST https://sandboxapi.p.rapidapi.com/v1/sessions/sess_abc/execute \
  -H "X-RapidAPI-Key: $RAPIDAPI_KEY" \
  -H "X-RapidAPI-Host: sandboxapi.p.rapidapi.com" \
  -H "Content-Type: application/json" \
  -d '{"code":"public class Main{public static void main(String[] a)throws Exception{int x=Integer.parseInt(java.nio.file.Files.readString(java.nio.file.Path.of(\"/home/sandbox/state.txt\")).trim());System.out.println(x*2);}}"}'
Read the sessions docs →

Need more? Get API access

Integrate secure code execution into your own apps with our REST API. Basic includes 500 requests per RapidAPI subscription period.