Format Java code

Paste Java code squeezed onto one line or poorly indented: the tool re-indents every { } block (classes, methods, conditions, loops) and puts one statement per line, for instant readability.

Note: this is a basic indentation formatter, not a full tool like google-java-format. It doesn't check that the code compiles and doesn't rearrange every space around operators.

Example:

How it works

The code is scanned character by character by a small state machine that tells code apart from strings (single and double quotes) and comments (//, /* */), so it never splits a brace or semicolon that sits inside a string. Each opening brace increases the indentation by 4 spaces, each closing brace decreases it, and each semicolon outside parentheses ends a line.

Can the reformatted code stop compiling?

No: only the presentation changes (spaces, line breaks, indentation), never the logic of the code. Class, method and variable names stay strictly identical.

Are imports and annotations handled correctly?

import statements end with a semicolon and therefore follow the same rule as other statements (one per line). Annotations such as @Override are treated as regular text and stay right before the element they annotate.

Formatting runs 100% locally in your browser: your Java code is never sent to a server.