Skip to content
AgileLogics

Java Editor

Write and edit Java with syntax highlighting, right in your browser.

Loading editor…

What Java is used for

Java is a statically typed, object-oriented language that compiles to bytecode and runs on the Java Virtual Machine (JVM), so the same program runs on Windows, macOS and Linux. It's used for back-end web services (often with Spring Boot), Android apps, enterprise systems, big-data tools such as Hadoop and Kafka, and as a teaching language in many computer science courses.

This online Java editor lets you write or clean up a class without installing an IDE. It highlights keywords, types, strings, numbers, comments and annotations, matches braces, auto-closes brackets and quotes, and indents new lines inside blocks. The toolbar adds find and replace, word wrap, a dark theme, fullscreen, copy, and Download, which saves the code as Main.java.

There is no compiler behind the page. It won't run main, print output, or flag a missing semicolon. The highlighter is based on Java's reserved words, so newer contextual keywords such as record, sealed, permits and yield show up uncoloured.

Example: grouping records with streams

Paste this in to try it. It uses a record (Java 16+), List.of and a stream collector, and needs JDK 16 or newer to run:

import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;

public class Main {

    record Book(String title, String author, int year) {}

    public static void main(String[] args) {
        List<Book> books = List.of(
            new Book("Dune", "Frank Herbert", 1965),
            new Book("Neuromancer", "William Gibson", 1984),
            new Book("Count Zero", "William Gibson", 1986)
        );

        Map<String, Long> booksPerAuthor = books.stream()
            .collect(Collectors.groupingBy(Book::author, TreeMap::new, Collectors.counting()));

        booksPerAuthor.forEach((author, count) ->
            System.out.println(author + ": " + count));
    }
}

Because the map is a TreeMap, authors come out in alphabetical order:

Frank Herbert: 1
William Gibson: 2

Compiling and running it

  1. Click Download. The file saves as Main.java, which matches the public class Main above.
  2. Install a JDK and confirm it with java -version.
  3. For a single file, run it directly with java Main.java. Since JDK 11 the launcher compiles the source in memory and runs it (JEP 330).
  4. For larger projects, compile first with javac Main.java, which writes Main.class, then run java Main. Multi-file projects are normally built with Maven or Gradle.

Java details worth getting right

File names follow public classes. The Java Language Specification, section 7.6 allows compilers to require that a public top-level class lives in a file of the same name, and javac enforces it. Source-file mode is the exception: java Main.java runs the first top-level class it finds whatever the file is called.

Compare strings with equals. == on two String objects checks whether they are the same object, not whether they hold the same characters. It can appear to work for literals, which the JVM interns, and then fail on strings built at runtime. Use a.equals(b) or Objects.equals(a, b) when either side might be null.

Contextual keywords are still valid names. JLS section 3.9 lists record, var, yield, sealed and permits as contextual keywords. You can still have a variable called record, which is also why simple highlighters don't treat them as reserved.

Integer division truncates. 7 / 2 is 3 because both operands are int. Write 7 / 2.0 or cast one side to double when you need 3.5.

Keep going with Java

The free Java course starts with your first Java program and later covers records in depth. For a one-page syntax reference, see the Java cheat sheet.

Last updated

Frequently asked questions

Can I compile or run Java in this editor?
No. The page has no JDK, so it doesn't compile or run anything and won't show output or compiler errors. Download the file and run it with java Main.java (JDK 11 or newer), or compile it with javac first.
Why does javac complain about the file name?
If the file declares a public class, javac requires the file name to match it, so public class Main must live in Main.java. The download is already named Main.java, so a class called Main compiles as is. For any other public class name, rename the file to match, or run it in source-file mode with java Main.java, which skips that check.
Why isn't record or sealed highlighted as a keyword?
Words like record, sealed, permits and yield are contextual keywords in Java, meaning they only act as keywords in certain positions. The highlighter colours Java's reserved keywords, so these newer words appear as plain identifiers. The code is still valid.
Is my code saved or sent to a server?
No. Your code stays in the browser tab and is never uploaded. Copy it or download it before you close the page.