Java Prettier - format and beautify Java in your browser
A Java formatter takes source that has been flattened onto one line, decompiled, hand-indented by three different people or pasted out of a chat window, and prints it again in one consistent style. This one works the way your IDE does: it parses the code into a real concrete syntax tree and prints that tree from scratch, so the layout is decided by the language structure rather than by counting braces. Everything happens inside your own tab - no JDK, no Maven, no Gradle, no upload.
Why an AST-based beautifier matters for Java
Regex beautifiers fall over on modern Java almost immediately. A { inside a text block is not a block. A < in Map<String, List<Integer>> is not a comparison. An arrow in a switch arm is not a lambda. Parsing the file properly is what lets the printer keep records, sealed interfaces and permits clauses, pattern matching for instanceof and switch with when guards, yield, triple-quoted text blocks, var, lambdas, method references, annotations in every position, generics with bounded and wildcard parameters, enum constant bodies, try-with-resources, multi-catch, labelled breaks, static and instance initialisers, and a whole module-info.java intact.
The same parse gives you a free syntax check. Paste something that does not compile and you get the exact line, the exact column and a caret pointing at the token that confused the parser - usually faster than waiting for a build.
The options, and what they actually change
Print width is a target rather than a hard limit: the printer fits what it can on a line and breaks the rest, so dropping it to 40 is the quickest way to watch a builder chain explode into one call per line. Indent style and indent size are the settings teams argue about; the three presets encode the common answers - Google Java Style at two spaces and 100 columns, AOSP at four and 100, Oracle/Sun at four and 80. Brace style switches between attached (K&R) and next-line (Allman) braces. The import and comment switches are the only ones that rewrite the code itself rather than its whitespace, and each is re-parsed before it is accepted.
Modes for different jobs
Format is the everyday mode. Unminify expands a decompiled or single-line blob into browsable structure - no identifier is ever renamed and no logic is altered. Compact removes the column limit so declarations stay on one line, which is what you want for a slide or a chat message. Diff shows exactly which lines the formatter would touch before you commit anything. Validate parses and reports only success or the first syntax error. Compare renders the same file under two presets side by side, so the cost of a style migration is visible before anyone opens the pull request.
Snippets are handled automatically. Leave the parse mode on Auto-detect and paste a bare method, a couple of fields or a run of statements: the tool tries a whole compilation unit first, then a class body, then bare statements, and tells you which one it used.
How the output is checked
Formatting is only allowed to move whitespace, so every run proves it. The printed source is read back by the same lexer and its token stream compared with the input's, token by token. Three liberties the printer is known to take are recognised and named rather than hidden: it re-indents text blocks (without changing the string they denote, which the check verifies using the incidental-whitespace rules from the language specification), it sorts each contiguous block of import declarations, and it may add parentheses around an expression it had to wrap. Anything else is reported as a failure instead of being handed back quietly.
Everything stays in your tab
The parser and printer are JavaScript, loaded on first use and run locally. Your source is never uploaded, never logged and never executed. Copy the result, download it as a .java file, or export the run as text or CSV - and take the generated .prettierrc and .editorconfig snippets with you so the same style is reproduced in CI.