Java Viewer, Formatter and Minifier
FV-44Paste Java and either lay it out cleanly with clang-format or shrink it by removing comments and spaces. Everything runs in your browser.
Runs in your browser. Nothing is uploaded.
Java code
Result
How to use it
- Paste your Java, or open a .java file or drop it on the input box.
- Pick a base style, indent and line width.
- Press Format to lay it out, or Minify to shrink it.
- Copy the result or download it as a .java file.
Format
Format runs clang-format with its Java support. The default Google style indents by two spaces; the indent choice here overrides it. Anything inside a block is indented, long argument lists wrap at the column limit, and comments, annotations and imports are kept where they are. It does not match google-java-format exactly, and it does not sort or remove imports.
Minify
Minify strips comments and collapses whitespace, and a space or line break stays only where removing it would change how the code reads. String literals, character literals and text blocks with triple quotes are copied as written, so a multi-line text block keeps its line breaks. Javadoc comments are removed too. Class, method and variable names are not changed.
What it cannot do
The formatter does not compile Java, so syntax mistakes are not reported. Minify only reports an unclosed string, character or comment. Pasting several classes in one box is fine, but the code is formatted as one file. Test minified output in your own build before relying on it.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Comment is never closed (missing */) (line 1, column 1). | A block comment was opened with /* and no */ was found. | Add the closing */ or remove the opening /* at the position shown. |
Questions people ask
How do I format Java code online?
Paste the Java into the box, choose a style and indent, and press Format. The output is laid out by clang-format and can be copied or downloaded as a .java file.
Does Minify keep my text blocks?
Yes. Text blocks, strings and characters are copied exactly as written, including their line breaks and indentation. Yes. Text blocks, strings and characters are copied exactly as written, including their line breaks and the spaces inside them, so the program behaves as before.
Is the result the same as google-java-format?
No. It is clang-format with a Java mode, so details such as import handling and some line breaks differ. No. It is clang-format with a Java mode, so details such as import handling and some line breaks differ. Check the output against your own style rules.
Will it find compile errors?
No. Format lays out any text and Minify only checks that strings, characters and comments are closed. Use javac for real errors. No. Format lays out any text and Minify only checks that strings, characters and comments are closed. Use javac or your build tool for real errors.
Does it sort my imports?
No. Import lines keep the order you gave them. Use your IDE or a build plugin if you need sorted imports. No. Import lines keep the order you gave them and unused imports stay. Use your IDE or a build plugin if you need sorted or cleaned imports.
About this tool
Format runs clang-format for Java, compiled to WebAssembly in your browser. The base style, indent and line width are your choices; the result may differ from google-java-format or your IDE. It formats text and does not compile it, so syntax errors are not reported. Minify removes comments and extra whitespace and keeps strings, characters and text blocks as written. It renames nothing and does not shorten identifiers. Imports are not sorted or removed.