Google Java style exploration

As a student major in computer science, I used Java at most of my time. Many times I found others code easy to understand but not mine. Finally, I force myself to work on a guide this time.

2.1 File name

The source file name consists of the case-sensitive name of the top-level class it contains (of which there is exactly one), plus the .java extension

Its intuitive to think keep all class name together. However, when I was only a beginner, I once wrote 2 class in a file in Sublime Text, made me hard to find out where bug is.

2.3.1 Whitespace characters

​ Aside from the line terminator sequence, the ASCII horizontal space character (0x20) is the only whitespace character that appears anywhere in a source file. This implies that:

  1. All other whitespace characters in string and character literals are escaped.
  2. Tab characters are not used for indentation.

usually I like use tab to indentation, when final came out, maybe can transfer \t -> 4 whitespaces.

3.3.1 No wildcard imports

Wildcard imports, static or otherwise, are not used.

even use * to import is very easy, but it will cause confusion, take the namespace, make the compiler import wrong package without error. It is better to only import the one we need. (Useful details)

Ordering of class contents

​ What is important is that each class uses some logical order, which its maintainer could explain if asked. For example, new methods are not just habitually added to the end of the class, as that would yield “chronological by date added” ordering, which is not a logical ordering.

Try to make code assemble as a logical block, this also works for every place.

5.2.1Package namesimg

Package names are all lowercase, with consecutive words simply concatenated together (no underscores). For example, com.example.deepspace, not com.example.deepSpace or com.example.deep_space.

Class names are written in UpperCamelCase.

Method names are written in lowerCamelCase.

Just follow the rule and improve the code. except static final variable, most of them follow lowerCamelCase