Skip to content

Java Guideline

Code Formatting

Code formatting is one of the first guidelines a code should respect. More than a way to indent your classes, the format allows code sourcing tools, just like Git, to compare code versions from an environment to an other environment. The format should result from a team agreement and be shared among its members. The best code format is the one everybody agrees with !

image

Now we will learn how to format source code inside the most used IDEs in the java world : IntelliJ and Eclipse. Before starting, you should now that it is possible to import Eclipse format to IntelliJ, but not the other way.

How to format in IntelliJ

  1. Click on File > Settings ...
  2. Go to Editor > Code Style > Java

From there, two solutions are available : <<<<<<< HEAD * The formatter can be edited manually by using the code style window in tabs Tabs and indents, Spaces, Wrapping and braces ... =======

  • The formatter can be edited manually by using the code style window in tabs Tabs and indents, Spaces, Wrapping and braces ...

    d3a8f6723e36c02cafab2615307610400445ec20

  • Import a format by clicking on the gear (next to Scheme) then on Import Scheme .... You may import a formatter from an Eclipse IDE or from another IntelliJ IDE

How to format in Eclipse

Go to Window > Preferences > Java > Code Style > Formatter then click on Edit .... You may now change Line wrapping, Method declarations ...

Note that you can import an Eclipse code format but not an IntelliJ code format.