Java Formatting – Eclipse

When I code in Java, this is what it looks like:

Formatted Java
Sample from the Eclipse Java Formatter

Every opening and closing brace containing code is on a separate line, and every block’s contents are indented. I prefer the “next line” opening brace method over the “same line” method for a couple of reasons:

  1. It’s easier to match opening and closing braces.
  2. To me, having braces at the same indentation level creates a better appearance of a block of code.

To change your indenting and braces settings in Eclipse, go to Window > Preferences > Java > Code Style > Formatter. Create a new profile for yourself, then edit your settings to your liking.

Alternatively, here is my current Eclipse Java formatter profile, if my style works for you.

Leave a Reply

Your email address will not be published. Required fields are marked *

two × three =