Java Language Oracle Official Code Standard Whitespace

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Vertical Whitespace

  • A single blank line should be used to separate…

    • Package declaration
    • Class declarations
    • Constructors
    • Methods
    • Static initializers
    • Instance initializers
  • …and may be used to separate logical groups of

    • import statements
    • fields
    • statements
  • Multiple consecutive blank lines should only be used to separate groups of related members and not as the standard inter-member spacing.

Horizontal Whitespace

  • A single space should be used…

    • To separate keywords from neighboring opening or closing brackets and braces
    • Before and after all binary operators and operator like symbols such as arrows in lambda expressions and the colon in enhanced for loops (but not before the colon of a label)
    • After // that starts a comment.
    • After commas separating arguments and semicolons separating the parts of a for loop.
    • After the closing parenthesis of a cast.
  • In variable declarations it is not recommended to align types and variables.



Got any Java Language Question?