OpenJDK 21

Java compiler API

Compile and run user-submitted Java with one HTTPS request. CodeForge compiles with javac (OpenJDK 21), runs your public class, and returns compiler output, stdout, stderr and the exit code.

Example: run Java with one request

Submit the source and stdin, then poll GET /v1/executions/{id} until it finishes.

The program
import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt();
        System.out.println(a * b);
    }
}
The request
curl -X POST https://api.tatvastack.com/v1/executions \
  -H "Authorization: Bearer $CODEFORGE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"language":"java","source":"import java.util.Scanner;\n\npublic class Solution {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int a = in.nextInt(), b = in.nextInt();\n        System.out.println(a * b);\n    }\n}","stdin":"6 7"}'
The result
{
  "executionId": "exe_…",
  "status": "SUCCEEDED",
  "language": "java",
  "stdout": "42\n",
  "stderr": "",
  "compileOutput": "",
  "exitCode": 0,
  "durationMs": …
}
FAQ

Java execution questions

Does my class have to be called Main?

No. Name your public class anything; CodeForge names the source file after it and runs it. Put main in that class.

How are compilation errors returned?

Status COMPILE_ERROR, with javac output in compileOutput, so you can show students or candidates exactly what went wrong.

Does compile time count against the time limit?

No. timeMs limits the program run; compilation has a separate budget.

Which Java version is used?

OpenJDK 21 (LTS).

Run Java in your product today

500 free runs a month during the beta. No servers to manage.

Read the quickstart Request beta access