Skip to content

Java Online Compiler

Compile and run Java 17 with Scanner input, without installing a JDK.

Main.java
Open in K-Programmer ↗ Free course Ctrl+Enter runs · Tab indents · Esc then Tab leaves the editor
Output
 

Runs on K-Programmer's sandboxed compiler (OpenJDK 17): 5 s time limit, 512 MB memory, no network.

Report a problem

Don't include personal or sensitive information.

What happened, and what did you expect? (10–2000 characters) 0 / 2000

Your browser and system, screen size and recent error messages on this page. Never what you typed or your files. Privacy

What is sent
 

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

  1. Choose a sample or write a class with a public static void main(String[] args) method.
  2. Type the input for Scanner in the Input box.
  3. Click Run or press Ctrl+Enter.
  4. Read the output, or the javac errors with line numbers, and fix your code.
  5. 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 Scanner and BufferedReader
  • 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).