Java Formatter
Format Java source code with Prettier and prettier-plugin-java: classes, records, lambdas, generics and long call chains.
Runs in your browserJava → Java
Loading tool…
Example
public class Hello{public static void main(String[] args){System.out.println("Hi");}}public class Hello {
public static void main(String[] args) {
System.out.println("Hi");
}
}How to use the Java Formatter
- Paste a complete compilation unit (a class, interface, enum or record), or load a .java file.
- The output follows the prettier-java style, which adds a blank line before the first class member.
Privacy and limitations
- Your data is processed on your device and is not uploaded to any server.
- The input must be syntactically valid Java; code fragments such as a lone statement or method cannot be formatted.
- Syntax errors are reported without a line number because the parser does not expose one.
- The style is fixed to prettier-java conventions; only indentation and print width are configurable.
Frequently asked questions
Is my code uploaded?
No. The parser is a WebAssembly module that runs in your browser; it is downloaded the first time you format.
Related converters
Java Syntax HighlighterHighlight Java classes, annotations and generics and export them as styled HTML snippets.JSON to Java ClassGenerate Java POJO classes with Jackson annotations, getters and setters from sample JSON.Java String EscapeEscape text for a Java string literal: backslashes, quotes, \n, \t and control characters, optionally as \uXXXX ASCII.PHP FormatterFormat PHP code with Prettier and the official PHP plugin, PSR-12 style, with a target PHP version setting.GraphQL FormatterFormat GraphQL queries, mutations, fragments and schema definitions (SDL) with Prettier.Markdown FormatterNormalise Markdown with Prettier: consistent list markers, headings, emphasis and table alignment.HTML BeautifierBeautify HTML with Prettier: consistent indentation plus formatting of embedded CSS and JavaScript.Less FormatterFormat Less stylesheets with Prettier, keeping variables, mixins and nested rules readable.