Online Java Compiler
Run Java without installing the JDK. Type, press Run, see the output.
About this Java compiler
This free online Java compiler runs your code with Java 15 on our server. You do not need to install the JDK or set up an IDE. Read input with Scanner and type it in the terminal while the program runs. The output and any errors show below the editor.
Use it for college lab programs, OOP practice and interview questions.
How to use it
- Write a class with a public static void main(String[] args) method.
- You can name the class Main or any other name. The file name is chosen for you from the public class.
- Press Run, then type the input for Scanner in the terminal and press Enter.
Java examples
Open any of these from the Examples tab in the side bar.
Hello, World
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Read a name with Scanner
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String name = sc.nextLine();
System.out.println("Hello, " + name + "!");
}
}
A simple class
public class Main {
static class Student {
String name;
int marks;
Student(String name, int marks) {
this.name = name;
this.marks = marks;
}
boolean passed() {
return marks >= 40;
}
}
public static void main(String[] args) {
Student s = new Student("Ravi", 72);
System.out.println(s.name + " passed: " + s.passed());
}
}
What is Java?
Java is used for Android apps, banking systems and large company software. Many service companies in India hire Java developers, so it is a common first language for placements.
Java code is compiled to bytecode first, and then the Java Virtual Machine (JVM) runs it. This makes the first run a little slower than C, but the language is safer: there are no raw pointers, and memory is cleaned up for you.
Common errors and how to fix them
class X is public, should be declared in a file named X.javaKeep only one public class. This compiler names the file after it.cannot find symbolA variable, method or class name is spelled wrong, or an import is missing.NoSuchElementExceptionScanner tried to read more input than you typed. Add the missing input values.
Frequently asked questions
Which Java version is used?
Java 15 (OpenJDK). Features such as var, switch expressions and text blocks work.
Must my class be called Main?
No. Any public class name works. The compiler names the file after your public class.
How do I read input?
Use Scanner sc = new Scanner(System.in); then type the input in the terminal when the program asks. You can also put it in the Input box before you press Run.
Why is the first run slower than C?
Java compiles your code and then starts the JVM. This adds about one second. The program itself is fast.
Do I need an account?
No. It is free without an account. A free account gives higher limits: longer run time and bigger programs.
Other free compilers
Learn to code with DevHives
Step-by-step lessons, DSA problems with a judge and mock interviews — made for students in India.
Create a free account