Google Java Style Guide – Complete Definition and Coding Standards
This article presents the full Google Java Style Guide, detailing file naming, UTF‑8 encoding, whitespace rules, brace placement, import ordering, naming conventions for packages, classes, methods, constants, and Javadoc formatting, with numerous code examples illustrating each rule.
This document provides the complete definition of Google’s Java programming style guide, outlining the conventions that a Java source file must follow to be considered compliant.
File basics : source files are named after the top‑level class with a .java extension, encoded in UTF‑8, and use only ASCII space (0x20) as whitespace.
Whitespace and formatting : no tabs, two‑space indentation, 80‑ or 100‑character line limits, and specific rules for blank lines, spaces around operators, commas, and braces. Braces follow the K&R (Egyptian) style, always present even for single statements.
Import statements : no wildcard imports, each import on its own line, grouped and ordered (static imports, com.google, third‑party, java, javax) with a blank line between groups.
Naming conventions : packages are all lower‑case; class names use UpperCamelCase; method, variable, parameter, and non‑constant field names use lowerCamelCase; constants use CONSTANT_CASE; type variables are single capital letters or UpperCamelCase ending with T . Examples include:
private int x; // fine
private Color color; // fine
private x; // permitted but not recommendedModifiers and annotations : modifiers appear in the order prescribed by the Java Language Specification; annotations are placed on their own line unless a single annotation can share the line with the declaration.
Javadoc : every public class and its public/protected members should have Javadoc with a brief summary, proper paragraph tags, and standard tags (@param, @return, @throws, @deprecated) in the correct order. Simple getters may omit Javadoc, and overridden methods are exempt.
Programming practices : always use @Override when applicable, avoid empty catch blocks without comment, do not override Object.finalize , and call static members via the class name.
The guide also includes extensive examples of array initialization, switch statements, and comment styles, reinforcing the emphasis on readability, consistency, and maintainability in Java code.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.