# Java Formatter

Format Java source code with the Prettier Java plugin for consistent indentation, brace placement, spacing and line wrapping. Paste a class, record, interface or snippet with modern features such as records, sealed types, switch expressions and text blocks, choose 2 or 4 spaces or tabs and a print width, and copy back clean code ready for review, documentation or a pull request.

## Frequently asked questions

### Which engine formats the code?

The tool runs Prettier 3 with prettier-plugin-java 2.11, which parses Java with a tree-sitter grammar on the server. The same code always produces the same output.

### Which Java versions are supported?

Current Java syntax is supported, including records, sealed classes and interfaces, pattern matching, switch expressions, text blocks, var and lambdas. Older Java 8 code formats as well.

### What is the default indentation?

Four spaces per level, the most common Java convention. You can switch to 2 spaces or tabs, and set the print width from 40 to 200 characters, 80 by default.

### Does the input have to be a complete file?

No. Complete files with a package, imports and type declarations work best, but snippets such as a single class or a few statements are accepted too. The snippet only has to parse as Java.

### How are syntax errors reported?

When the problem is an unbalanced brace, parenthesis or bracket, or an unclosed string or comment, the error names its line and column. For other mistakes the parser only reports that the code is not valid Java, sometimes naming the missing token.

### Are comments and Javadoc preserved?

Yes. Line comments, block comments and Javadoc stay attached to the code they belong to. Their text is not reflowed.

### Will the formatter reorder imports or members?

No. Imports, fields and methods stay in their original order. Only whitespace, line breaks and indentation change.

### Can I format Android or Spring code?

Yes. Annotations, generics and framework code are ordinary Java, so Android activities, Spring controllers and similar classes format the same way.

### How large can the input be?

Up to 1 MB of source text per request, which covers even very large classes. Formatting stops after 10 seconds.

### Is my source code stored?

No. It is formatted in memory and sent straight back. The service records only the size of the request, never its content.

Your ad here?

[Email us](mailto:hi@dennn.is?subject=Advertising%20on%20OneClick%20Pro)

[Ad The agent-ready plugin suite for WordPress.](https://sleekwp.com/?ref=oneclickpro)
