Online Java compiler

Write Java, give it input and run it, in your browser. Compile errors use javac's own words, each one is explained in plain English, and the visualizer can replay any run step by step.

Opening the compiler…

About the Java compiler

How to use the Java compiler

Write a program in the editor or pick a template: input and arithmetic, arrays, strings, methods and recursion, a class, inheritance, ArrayList and HashMap, exceptions, generics, and lambdas with streams. Press Run or Ctrl+Enter. Your program needs a class with public static void main(String[] args); the class can have any name, and you can put several classes in one file.

How input works

Type what the program will read into the Input tab before you press Run, as you would in a terminal. new Scanner(System.in) with nextInt(), next() and nextLine() reads it, and so does a BufferedReader around System.in. If the program asks for more than you gave, Scanner throws NoSuchElementException, and the compiler tells you the program wanted more input.

What runs your code

This is StepVioz's own implementation of Java 17, and it works entirely in your browser, with no server and no JVM download. It checks your program as javac does: types, missing returns, uninitialized variables, unhandled checked exceptions. Then it translates the program to JavaScript, so loops and recursion run fast. Its output is tested against a real JDK on over a hundred programs, and its error messages against javac's.

The usual library is there: String and StringBuilder, Math, the wrapper classes, ArrayList, LinkedList, HashMap (which prints in the same order as real Java), TreeMap, HashSet, PriorityQueue, ArrayDeque, Arrays, Collections, Optional, streams and Collectors, BigInteger and Random. Records, enums, generics, lambdas, inner classes, switch expressions and text blocks all work.

Each run may take 5 seconds; then it is stopped. Output is kept up to 10,000 lines or 1 MB, and the rest is cut with a notice. Programs cannot reach the network, and no packages or libraries can be installed: what a language brings with it is what you can use. A loop that never ends is stopped at 5 seconds, keeping what it printed.

Some things are different from a real JVM. A thread started with start() runs straight through to its end, so output never interleaves. Files, networking, reflection and BigDecimal are not available. Recursion can go about 9,000 calls deep.

See it step by step

Visualize this run opens the program and its input in the Java visualizer, which shows each method's frame, its variables, and arrays and objects on the heap, with arrows for references. It is the clearest way to see why two variables can change the same object. It follows the first 1,000 steps.

Questions

Is this online Java compiler free?
Yes. There is no sign-up and no limit on how many programs you run.
Does my code go to a server?
No. It is compiled and run inside your browser, in a sandbox with no network access. Nothing you write is uploaded.
Which version of Java is it?
It follows Java 17: var, records, switch expressions, text blocks and pattern matching for instanceof all work.
Does my class have to be called Main?
No. Any class with public static void main(String[] args) will do, and one file can hold several classes.
Why do I get cannot find symbol for Scanner?
Scanner lives in java.util, so the file needs import java.util.Scanner; or import java.util.*; at the top. String, Math and System are in java.lang and need no import.

See also