Official document: Google Java Style
Chinese translation: Google Java Programming style guide, Hawstein ' s Blog
Can read the official documents first, encountered uncertainty in doubt, can be compared to the translation version of reading, deepen understanding.
5.2.1 Package Name
The package name is all lowercase letters, which simply connect consecutive words in the previous (without underlining).
For example: Use com.example.deepspaceinstead of com.example.deepSpace or com.example.deep_space.
5.3 Camel-style naming method
Name starting with a phrase:
- Converts a phrase to a pure ASCII code and removes any single quotation marks. For example: "Müller ' s Algorithm" will become "Muellers algorithm".
- Divide the result into words, separated by spaces or other punctuation (often hyphens).
- Recommendation: If a word already has a common hump representation, split it up by its composition (such as "AdWords" will split into "ad words"). It is important to note that "IOS" is not a real hump representation, it violates the Convention, so this recommendation does not apply to it.
- lowercase all letters (including abbreviations) and capitalize the first letter of a word:
- Capitalize the first letter of each word to get a big hump-named (uppercamelcase)
- In addition to the first word, the first letter of each word is capitalized to get the small hump-type name (Lowercamelcase)
- Finally, link all the words together to get a representation.
Example
Prose Form |
Correct |
Incorrect |
"XML HTTP Request" |
XmlHttpRequest |
XMLHTTPRequest |
"New Customer ID" |
newCustomerId |
newCustomerID |
"Inner Stopwatch" |
innerStopwatch |
innerStopWatch |
"Supports IPV6 on IOS?" |
supportsIpv6OnIos |
supportsIPv6OnIOS |
"YouTube Importer" |
YouTubeImporter
YoutubeImporter * |
* Indicates yes, but not recommended.
Google Java Style Reading essays