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
- Click Download. The file saves as
Main.java, which matches thepublic class Mainabove. - Install a JDK and confirm it with
java -version. - 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). - For larger projects, compile first with
javac Main.java, which writesMain.class, then runjava 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