NV ToolkitFormat · Validate · Convert

Formatters

Java Formatter

Fast structural beautification for Java — braces aligned, nesting indented, readable in one click.

In short

Beautify Java code online: braces, indentation and statement layout cleaned up instantly in your browser — generics and annotations preserved.

By NaveenKumar T · Updated

Learn: JSON Examples: From Hello World to Real API Payloads

  • Industry-standard formatting
  • Exact error line & column
  • 2/3/4-space or tab indent

Runs entirely in your browser — nothing you paste or open here is uploaded, logged, or stored.How we handle data →

Example

Java Formatter: input and output

A billing-period helper pasted from a code review comment: two imports on one line, fields and a constructor with an argument check squashed together, and a loop that builds a `List<LocalDate>`.

Input · java
import java.time.*;import java.util.*;
public class BillingPeriod{
private final LocalDate start;private final LocalDate end;
public BillingPeriod(LocalDate start,LocalDate end){if(end.isBefore(start)){throw new IllegalArgumentException("end before start");}this.start=start;this.end=end;}
public List<LocalDate> dueDates(int everyDays){List<LocalDate> dates=new ArrayList<>();for(LocalDate d=start;!d.isAfter(end);d=d.plusDays(everyDays)){dates.add(d);}return dates;}
@Override public String toString(){return start+" to "+end;}
}
Output · java
import java.time.*;
import java.util.*;
public class BillingPeriod {
  private final LocalDate start;
  private final LocalDate end;
  public BillingPeriod(LocalDate start, LocalDate end) {
    if (end.isBefore(start)) {
      throw new IllegalArgumentException("end before start");
    }
    this.start = start;
    this.end = end;
  }
  public List < LocalDate > dueDates(int everyDays) {
    List < LocalDate > dates = new ArrayList < > ();
    for (LocalDate d = start; !d.isAfter(end); d = d.plusDays(everyDays)) {
      dates.add(d);
    }
    return dates;
  }
  @Override public String toString() {
    return start + " to " + end;
  }
}

Braces, nesting and one-statement-per-line layout are restored, but `List<LocalDate>` comes out as `List < LocalDate >` because js-beautify treats `<` and `>` as comparison operators — still valid Java, just spaced unusually.

Learn more

Formatting Java, properly

Java's C-style structure — braces, statements, parameter lists — beautifies cleanly with the js-beautify engine this page uses: a fast, forgiving formatter that restores indentation and line structure without requiring a full compilation unit. Generics, annotations, and lambdas pass through intact.

Ideal for the everyday cases: a method pasted from a PR comment, decompiled output, a snippet logged without formatting. For enforced house style across a repo, pair your IDE with google-java-format; for instant readability of any fragment, this page is quicker.

Help

Frequently asked questions

Everything you need to know about the Java Formatter.

01How do I format Java code here?

Paste your Java (or load a file/URL) and press Format. This page runs js-beautify for fast structural beautification — braces aligned and statements laid out one per line — rather than a full compiler-grade formatter; see the FAQs below for what that trade-off means for generics and lambdas.

02Is this google-java-format?

No — full Java style engines need a compiler-grade parser that doesn't run in a browser. This is structural beautification: correct indentation and brace layout for any fragment, instantly. For AOSP/Google-style enforcement, run google-java-format in your build; for reading and sharing snippets, this does the job.

03Why do generics come out as `List < String >`, and what happens to lambdas?

js-beautify tokenizes with JavaScript's operator table, so `<` and `>` are spaced like comparisons: `Map<String, List<Integer>>` becomes `Map < String, List < Integer >>` and `new ArrayList<>()` becomes `new ArrayList < > ()`. Both still compile; only the spacing is unusual. Lambdas are different — `->` is not a JavaScript token, so `x -> x.qty()` is printed `x - > x.qty()`, which does not compile. Rejoin those by hand or paste bodies without lambdas. Annotations and `record` declarations pass through untouched.

Keep working

Related tools

Learn the format

Related guides

All guides →