Runtime: OpenJDK 17 LTS

Java Online Compiler (OpenJDK 17 LTS)

Compile and run Java 17 programs in your browser with Compilra’s OpenJDK 17 LTS environment. Test Scanner(System.in) and BufferedReader inputs supplied before execution alongside Records, Stream pipelines, and Collections without local JDK setup.

Why Use Compilra’s Java Online Compiler?

OpenJDK 17 LTS Environment

Write Java 17 using Records, switch expressions, sealed classes, Stream API pipelines, and Collections without configuring local JDK paths.

Pre-Supplied Scanner(System.in)

Enter console input in the Stdin panel before pressing Run so Scanner and BufferedReader programs read it cleanly.

Formatted JVM Stack Traces

Catch compile-time javac diagnostics and runtime JVM exceptions with exact line numbers in the integrated output panel.

How to Use Compilra’s Java Online Compiler

Compile and run OpenJDK 17 programs in four steps.

Step 01

Define public class Main

Ensure your entry class is named Main with a standard public static void main(String[] args) method.

Step 02

Configure Stdin for Scanner

Enter pre-supplied tokens or lines in the Stdin panel before running when testing Scanner(System.in).

Step 03

Compile with OpenJDK 17

Press Run Code (Ctrl+Enter) to invoke javac and execute the compiled bytecode on the JVM.

Step 04

Review Output & Stack Traces

Examine System.out output, exit codes, and any exception details in the terminal.

Worked Example: OpenJDK 17 Scanner(System.in) Example

Read integer counts and values with java.util.Scanner and format the average output.

Source CodeOpenJDK 17 LTS
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int total = 0;

        for (int i = 0; i < n; i++) {
            total += sc.nextInt();
        }

        double avg = (double) total / n;
        System.out.printf("Items: %d, Total: %d, Avg: %.1f%n", n, total, avg);
        sc.close();
    }
}
Pre-Supplied Stdin (Input)
3
15 40 45
Verified Output (Stdout)
Items: 3, Total: 100, Avg: 33.3

Enter input tokens in Standard Input (stdin) before clicking Run; Java reads the pre-supplied buffer cleanly from System.in.

Frequently Asked Questions

What is the required class name for Java programs on Compilra?

The primary entry class must be named Main (i.e., public class Main { public static void main(String[] args) { ... } }).

Which version of Java does Compilra run?

Compilra runs OpenJDK 17 LTS, which includes Java 17 capabilities like records, enhanced switch expressions, sealed classes, text blocks, and the Stream API.

Can I read user input using java.util.Scanner?

Yes. Instantiate Scanner(System.in) and enter your input values in the Standard Input (stdin) panel before pressing Run—input is pre-supplied prior to execution rather than typed live.

Are standard Java utility packages pre-installed?

Yes. All standard Java packages (java.util, java.io, java.math, java.time, java.net) are supported without extra configuration.

Does Compilra support Java 17 Records and Sealed Classes?

Yes. OpenJDK 17 LTS provides first-class support for record classes, enhanced switch expressions, sealed types, and text blocks.

How are Java runtime exceptions and stack traces handled?

When a runtime exception occurs (such as NullPointerException or ArrayIndexOutOfBoundsException), the JVM renders the formatted stack trace with line numbers in stdout/stderr.

Ready to write and run Java code?

Launch OpenJDK 17 LTS in your browser and test Java classes, streams, and algorithms right away.

Open Java Compiler