Overview
Paste Java source with inconsistent indentation or brace placement and get it reformatted with one brace per new line and four-space indentation that tracks nesting depth accurately. Unlike a naive regex reformatter, this tool first tokenizes the input into code, string literals, char literals, and comments (both // and /* */ styles) so that a brace or semicolon that happens to sit inside a string, a char literal, or a comment is never mistaken for real code structure - only actual code braces drive indentation. Java 15+ text blocks (triple-quoted strings) are explicitly unsupported and rejected with a clear message rather than silently mishandled, since they can contain unescaped braces and quotes that this tokenizer isn't built to track. Runs entirely client-side - nothing you paste is uploaded.
Best for: Cleaning up inconsistently indented Java pasted from a chat or ticket
How to use this tool
- Paste Java source. Code with inconsistent indentation, brace placement, or line breaks.
- The tokenizer separates code from literals. Strings, char literals, and comments are identified first so their contents are never touched.
- Braces drive indentation. Only real code braces increase or decrease nesting depth, tracked with a running counter.
- Copy the reformatted output. Four-space indentation, one brace per line, with else/catch/finally kept on the closing line.
Why use this tool
String and comment aware
A brace or quote inside a string, char literal, or comment never throws off indentation.
No hidden logic changes
Only whitespace, indentation, and line breaks change - identifiers and logic are untouched.
Honest about its limits
Java text blocks are explicitly rejected rather than reformatted incorrectly.
Client-side only
Nothing you paste is sent to a server - formatting happens entirely in your browser.
Frequently asked questions
No - there is no lightweight, dependency-free Java AST parser available for the browser. Instead, this tool uses a tokenizer that correctly separates strings, char literals, and both comment styles from real code before reindenting based on brace depth, which avoids the most common failure mode of naive formatters: braces or quotes inside a string or comment being miscounted as code structure.
Java 15+ triple-quoted text blocks ("""…""") can contain unescaped braces, quotes, and newlines that don't follow normal string-literal escaping rules. Rather than risk silently corrupting a text block's contents, this tool detects them and rejects the input with a clear message instead of guessing.
No - only whitespace, line breaks, and indentation are changed. Identifiers, literals, and logic are copied through unchanged.