Run Java without installing anything. This online Java compiler uses OpenJDK 17: your code is compiled with javac and run on the JVM in a secure sandbox on the K-Programmer engine. Records, var, text blocks, switch expressions and the whole standard library (java.util, java.math, streams) are available.
Programs read input with Scanner or BufferedReader from the Input box. Name your class whatever you like: the file is named after the public class automatically (or Main). Six samples get you started, and your code is saved in your browser.
How to use the Java Online Compiler tool
- Choose a sample or write a class with a
public static void main(String[] args)method. - Type the input for
Scannerin the Input box. - Click Run or press Ctrl+Enter.
- Read the output, or the
javacerrors with line numbers, and fix your code. - Share it with Share code or continue in K-Programmer.
Why use ToolOrca Java Online Compiler
- OpenJDK 17: records, var, text blocks, switch expressions, streams
- Standard input for
ScannerandBufferedReader - Any public class name; the file name is set for you
- Compiler errors, exceptions with stack traces, exit code and run time
- Syntax highlighting, line numbers, auto-indent, Ctrl+Enter
- Six samples, autosave and share links
Reading input with Scanner
Create one Scanner in = new Scanner(System.in) and read with in.nextInt(), in.next() (one word) or in.nextLine() (a whole line). The values come from the Input box, which you fill in before running.
A NoSuchElementException means the program tried to read more than you typed. After nextInt(), call nextLine() once before reading a full line, because the rest of the number's line is still waiting.
Class names, packages and limits
Write one file with one public class; the compiler saves it as ClassName.java. Leave out package lines. Other classes can sit in the same file without public, or as nested static classes like in the samples.
Each run has 5 seconds and 512 MB of memory (the JVM uses part of it), and no network access. The JVM needs a moment to start, so the first output takes slightly longer than C.
Learn Java with exercises
The samples go from System.out.println through input, loops, arrays and ArrayList, methods and classes, to selection sort with binary search.
For a full Java course with quizzes and auto-graded coding exercises, open your code in K-Programmer.
Frequently asked questions
Which Java version is it?
OpenJDK 17 (Eclipse Temurin), compiled with javac and run on the JVM.
Does my class have to be called Main?
No. The file is named after your public class. Without a public class, Main is used.
How do I give input to Scanner?
Type it in the Input box before clicking Run. Each nextInt() or next() takes the next value; nextLine() takes the rest of a line.
How do I share my code?
Click Share code. The link that is copied contains your code and input, compressed, after the # sign, so nothing is stored on a server and the link works as long as you keep it.
What is "Open in K-Programmer"?
K-Programmer is a free platform for learning to code, with lessons, quizzes, contests and the same online compiler. The button copies your code and opens K-Programmer, where you choose the language, paste the code and keep working (sign in to save programs).