Help
  • Paste Java code on the left and the right side is formatted instantly. A .java file can be dropped into the left box too
  • Indentation defaults to 4 spaces (traditional Java style); 2 spaces is also available

Java Formatter

This free online Java formatter rewrites Java code right in your browser: indentation, line breaks and spacing are cleaned up in one pass, so code copied from an IDE, a log or a chat message becomes readable again.

Formatting is done by Prettier's Java engine (prettier-plugin-java), which works on the real Java syntax tree instead of simply indenting on braces. Long method parameters, method chains, array initializers, lambdas and generics are wrapped correctly.

All tools on this site run entirely in your browser locally. No data is uploaded to any server.

Features:

  • Format Java: consistent indentation (4 or 2 spaces), brace placement, spacing around operators and commas
  • Auto wrap: long parameters, method chains and conditions are split across lines instead of staying squeezed on one line
  • Keeps meaning: only whitespace and line breaks change; identifiers, string contents, comments and annotation arguments stay as they are
  • Live formatting: type on the left and the right side is formatted as you go, or press the format button to re-run it
  • Code folding: fold by brace level, collapse or expand every class, method and block at once

Common uses:

  • Restoring Java code that was squashed into one line (from logs, emails or IM) into a readable layout
  • Tidying sample code copied from the web before pasting it into an IDE
  • Formatting both sides before comparing two Java files, so the diff shows only real logic changes