Simple JAVA Editor Online
public class MyClass {
public static void main(String args[]) {
int x=10;
int y=25;
int z=x+y;
System.out.println("Sum of x+y = " + z);
}
}
About This Java Editor
Java is statically typed, compiled to bytecode and run on the JVM, which is why the same jar runs on any platform with a runtime. The language has moved quickly since the six-month release cadence began: records, sealed types, switch expressions, text blocks and pattern matching all arrived in the last few versions.
The editor highlights classes, generics, annotations and text blocks, and matches braces across long class bodies.
Modern Java syntax
| Syntax | What it does |
|---|---|
record Point(int x, int y) {} |
Immutable data carrier with constructor, accessors, equals, hashCode and toString generated. |
var list = new ArrayList<String>(); |
Local type inference. The variable is still statically typed. |
String s = switch (day) { case MON -> "start"; default -> "other"; }; |
Switch expression - returns a value, no fall-through. |
if (o instanceof String s && !s.isEmpty()) |
Pattern matching for instanceof; s is in scope and already cast. |
String json = """\n {"a": 1}\n """; |
Text block. No escaping, incidental indentation stripped. |
list.stream().filter(p).map(f).toList() |
Stream pipeline. toList() since Java 16 replaces collect(Collectors.toList()). |
sealed interface Shape permits Circle, Square {} |
Restricts which types may implement it, so switch can be exhaustive. |
Optional<User> findById(long id) |
Signals that absence is expected, rather than returning null. |
Classic Java pitfalls
- String comparison.
==compares references. Use.equals(), and prefer"literal".equals(value)so a null value cannot throw. - Integer caching. Boxed values from -128 to 127 are cached, so
==onIntegerworks for small numbers and silently fails for large ones. - Checked exceptions in lambdas. The standard functional interfaces do not declare them, so anything that throws a checked exception has to be wrapped inside the lambda.
- Mutating a collection while iterating throws ConcurrentModificationException. Use
removeIfor an explicit iterator. - float and double for money. Use
BigDecimal, and construct it from a String, not a double.
Your Code Never Leaves Your Browser
The editor is JavaScript running in this tab. Nothing you type is posted to a server, stored, logged or associated with you, and there is no account and no autosave. That makes it safe to paste a snippet from a private codebase in order to read it with highlighting. The trade-off is that nothing persists either — refresh the page and your content is gone, so copy anything you want to keep.
Frequently Asked Questions
Can I compile Java here?
No. Compiling needs a JDK, and this page has no runtime - it is an editor for reading and formatting code. Nothing you type leaves your browser.
Is Java the same as JavaScript?
No. The names are a marketing artefact from 1995. They differ in typing, runtime, memory model and standard library; the only real similarity is C-style syntax.
What is the difference between JDK, JRE and JVM?
The JVM executes bytecode. The JRE is the JVM plus the standard library needed to run an application. The JDK is the JRE plus the compiler and developer tooling needed to build one.
Editors for Other Languages
Same editor, configured for a different language, each with its own syntax reference.