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.
Define public class Main
Ensure your entry class is named Main with a standard public static void main(String[] args) method.
Configure Stdin for Scanner
Enter pre-supplied tokens or lines in the Stdin panel before running when testing Scanner(System.in).
Compile with OpenJDK 17
Press Run Code (Ctrl+Enter) to invoke javac and execute the compiled bytecode on the JVM.
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.
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();
}
}3 15 40 45
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.
Popular Java Tutorials & Guides
Practice core concepts step by step with runnable examples.
Java Stdin Input: Scanner nextInt(), nextLine(), and BufferedReader
Read integers and multi-word lines safely in Java OpenJDK 17 using Scanner with pre-supplied stdin without losing lines.
Java Variables and Primitive Data Types with Examples
Declare typed variables in Java including int, double, boolean, String, and local var (Java 10+).
Java Operators: Arithmetic, Logical, and Bitwise
Explore arithmetic (+, -, *, /, %), relational, and logical (&&, ||, !) operators in Java.
Java Input and Output: Scanner, System.out, and printf
Read inputs using java.util.Scanner and format output streams with System.out.printf.
Java Type Casting: Widening and Narrowing Conversions
Understand implicit widening conversions and explicit narrowing casts in Java.
Java If...Else and Ternary Conditional Statements
Implement decision-making logic using if, else if, else, and ternary operators.
Explore Other Online Compilers & Editors
Switch seamlessly to any of Compilra’s 10 browser-based execution environments.
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