Java Code Viewer
Paste Java and read it back with consistent line breaks around braces and statements. Formatting only — nothing is compiled.
What it does
The viewer inserts a newline and one indent after each {, a newline after each ;, and a newline before each }, then collapses the blank lines that creates. It does not parse Java, track nesting depth, or understand package, import, or class structure, so every brace level is indented the same single step.
Worked example
Input:
public class Main { public static void main(String[] args) { System.out.println("Hello"); } }
Output:
public class Main {
public static void main(String[] args) {
System.out.println("Hello");
}
}
Java-specific notes
- The semicolons in a classic
for (int i = 0; i < n; i++)header are broken onto separate lines, so for-loops need a manual rejoin. - Array initializers
{1, 2, 3}, annotations such as@Override, lambdasx -> x + 1, and text blocks"""..."""pass through, but braces inside them are still split. - Generic types such as
List<Map<String, Integer>>are left untouched.
When to use it
Turning a single pasted class or method from an email, a forum answer, or a stack trace into something scannable, or spotting an unbalanced block quickly. For project formatting use your IDE, google-java-format, or a Spotless / Checkstyle setup that actually parses the language.
Does it run or compile the code?
No. It only rewrites whitespace; the source is never executed.
Why is my for-loop split across three lines?
Each ; triggers a line break, including the two inside the loop header.
Does it enforce Google or Sun style?
No. It applies one fixed style: two-space indent, opening brace at line end.
Is my source uploaded?
No. Formatting happens in your browser.