Google Java Style

Last changed: December 19, 2013

1 Introduction
1.1 Terminology notes
1.2 Guide notes

2 Source file basics
2.1 File name
2.2 File encoding: UTF-8
2.3 Special characters
2.3.1 Whitespace characters
2.3.2 Special escape sequences
2.3.3 Non-ASCII characters

3 Source file structure
3.1 License or copyright information, if present
3.2 Package statement
3.3 Import statements
3.3.1 No wildcard imports
3.3.2 No line-wrapping
3.3.3 Ordering and spacing
3.4 Class declaration
3.4.1 Exactly one top-level class declaration
3.4.2 Class member ordering

4 Formatting
4.1 Braces
4.1.1 Braces are used where optional
4.1.2 Nonempty blocks: K & R style
4.1.3 Empty blocks: may be concise
4.2 Block indentation: +2 spaces
4.3 One statement per line
4.4 Column limit: 80 or 100
4.5 Line-wrapping
4.5.1 Where to break
4.5.2 Indent continuation lines at least +4 spaces
4.6 Whitespace
4.6.1 Vertical Whitespace
4.6.2 Horizontal whitespace
4.6.3 Horizontal alignment: never required
4.7 Grouping parentheses: recommended
4.8 Specific constructs
4.8.1 Enum classes
4.8.2 Variable declarations
4.8.3 Arrays
4.8.4 Switch statements
4.8.5 Annotations
4.8.6 Comments
4.8.7 Modifiers

5 Naming
5.1 Rules common to all identifiers
5.2 Rules by identifier type
5.2.1 Package names
5.2.2 Class names
5.2.3 Method names
5.2.4 Constant names
5.2.5 Non-constant field names
5.2.6 Parameter names
5.2.7 Local variable names
5.2.8 Type variable names
5.3 Camel case: defined

6 Programming Practices
6.1 @Override: always used
6.2 Caught exceptions: not ignored
6.3 Static members: qualified using class
6.4 Finalizers: not used

7 Javadoc
7.1 Formatting
7.1.1 General form
7.1.2 Paragraphs
7.1.3 At-clauses
7.2 The summary fragment
7.3 Where Javadoc is used
7.3.1 Exception: self-explanatory methods
7.3.2 Exception: overrides
7.3.3 Optional javadoc

Last changed: December 19, 2013