One , introduce   This document is Google Java Complete definition of programming specification . Prepared in accordance with this specification Java Source files can be called Google Style.  
Same as other programming specification guides , Norms not only include the structural aesthetics of code , It also includes some other industry conventions and commonly used standards . The specifications in this document are basically agreed standards in the industry , We try to avoid defining what's still controversial .
    1.1 Term description   Unless otherwise specified in this document , otherwise :
a,class( class ) General refers to ordinary class type ,enum Enumeration type ,interface Type and annotation type .
b,comment( notes ) Always means implementation comments( implementation comments ,/*
*/). We don't use “ Documentation Comments ” It's like that , And I will say it directly javadoc.   Description of other terms , It will be described separately in the document .     1.2 Document description
  The code in this document does not necessarily conform to all specifications . Even if the code follows Google Style, But this is not the only code specification . The optional formatting style in the example should not be a mandatory specification .
      Two , Source document foundation     2.1 file name  
The source filename is the top-level class Class name of ( Case sensitive ), add .java Suffix composition .( except file ).     2.2
Document code :UTF-8   Source file use UTF-8 code .     2.3 Special characters   2.3.1 space character  
Except for line breaks ,ASCII Horizontal white space character (0x20) Is the only space character supported in the source file . This means : a, Other white space characters will be escaped . b,Tab Character is not used as indent control .
    2.3.2 Special escape string   Any character that needs to escape a string representation ( for example \b, \t, \n, \f, \r, \',
\\ etc. ), In this way, the escape string is used , Instead of the octal number of the corresponding character ( for example \012) or Unicode code ( for example \u000a) express .     2.3.3
wrong ASCII character   For other non ASCII character , Direct use Unicode character ( for example ∞), Or use the corresponding Unicode code ( for example
\u221e) Escape , It's all allowed . The only thing to consider is , How to make the code easier to read and understand .  
be careful : in use unicode Code escape , Or even sometimes directly unicode When characters , Adding a note will help others to understand the code .   example :
Example Discussion
String unitAbbrev = "\u03bcs"; // "μs" Allowed, but there's no reason to do
String unitAbbrev = "\u03bcs"; Poor: the reader has no idea what this is.
new int[] {5, 6}  and  int a, b; Declare when needed , Complete initialization as soon as possible  
Local variables should not be declared habitually at the beginning of a statement block , It should be declared as close as possible to the place where it was first used , To reduce their use .
Local variables should be initialized at the time of declaration . If it cannot be initialized on declaration , Initialization should also be completed as soon as possible .     4.8.3 array
Array initialization : Similar to block code processing   Initialization of all arrays , Can be processed in the same format as block code . For example, the following formats are allowed :
Not like C Declare arrays in the same style   Brackets should be part of the variable type , So it shouldn't be with variable names . for example : Should be String[] args, instead of  mName, kName
.     5.2 Different types of identifier specifications   5.2.1 Package name   Package names are all lowercase , adopt . Connect all levels together . Underline should not be used .     5.2.2 Class name
  Naming of types , Use case character spacing that starts with an uppercase letter (UpperCamelCase).
class Nouns or noun phrases are commonly used in naming .interface Sometimes adjectives or adjective phrases can also be used in the naming of .annotation There is no clear and fixed specification .  
Naming test classes , Should start with the name of the class it tests , And add at the end Test ending . for example :HashTest , HashIntegrationTest.    
5.2.3 Method name   Method name , Use case character spacing starting with lowercase letters (lowerCamelCase). Method naming usually uses verbs or verb phrases .  
stay JUnit In the test method of , You can use underscores , Name used to distinguish test logic , The following structures are often used :test<MethodUnderTest>_<state> . for example :
testPop_emptyStack . Test methods can also be named in other ways .     5.2.4 Constant name  
Constant Names , Use all uppercase characters , Separate words with underscores .(CONSTANCE_CASE).  
Constant is a static member variable , But not all static member variables are constants . When you choose to use constant naming rules to name variables , You need to know if this variable is a constant . for example , If the state of this variable can change , So this variable is almost certainly not a constant . It's just that a variable that doesn't change is not enough to be a constant . Here is an example of constant and non constant :
          Constants are usually named by nouns or noun phrases .     5.2.5 Member variable name of non constant  
Naming non constant member variables ( Include static and non static variables ), use lowerCamelCase name . General use of nouns or noun phrases .     5.2.6 Parameter name  
Parameter naming adopts lowerCamelCase name . You should avoid using a single character as a naming method for parameters .     5.2.7 Local variable name  
Local variable adoption lowerCamelCase name . It is named relative to other types , It can be shorter and more relaxed .
But even so , Single letter naming should also be avoided , Except for temporary variables used in the loop .  
Even if the local variable is final, Unalterable , And it can't be considered a constant , It should not be named by constant .     5.2.8 Type name   There are two ways to name a type name :  
a, Single capital letter , Sometimes it's followed by a number .( for example ,E,T,X,T2).
b, Like class Same name ( see 5.2.2 section ), Followed by a capital letter .( for example ,RequestT,FooBarT).     5.3 Camel
case Definition of   Sometimes some phrases are written Camel case There are many ways to write . For example, some abbreviations , Or some combination :IPv6 perhaps iOS etc .
In order to unify the writing method ,Google style A kind of writing method which can be almost determined as one is given .   a, Convert all characters to ASCII character , And get rid of it ' Equal sign . for example ,
"Müller's algorithm"  Converted to "Muellers algorithm" .
b, Split the results of the previous conversion into words one by one . Divide from spaces and other remaining punctuation .     be careful : Some are already Camel
case 's words , It should also be split at this time .( for example AdWords Split into ad words). But for example iOS Words like that , It's not a Camel
case 's words , It's a word that people use by convention , So there's no need to split . c, After the top two , Convert all letters to lowercase first , Then change the first letter of each word to uppercase .
d, last , Connect all words together , Form a designator .   be careful : The original case rules of words , Should be completely ignored . Here are some examples :       *
Sign means acceptable , But not recommended .   be careful , Some words are in English , It can be used - connect using , Or not - Direct use . for example “nonempty” and
“non-empty” It's all right . therefore , Method name is checkNonempty perhaps checkNonEmpty It's all right .       Six , Programming practice    
6.1 @override Should be used   @override annotations As long as it's grammatical , Should be used .     6.2 Exception capture Should not be ignored  
Normally ,catch The abnormality of living should not be ignored , But they all need to be dealt with properly . For example, printing out the error log , Or if you don't think it's going to happen , Should be thrown again as an assertion exception .  
If this catch It really doesn't need to be handled , It should also be explained by notes . for example :      
exception : In the test class , Sometimes the specified exception is thrown for the method , Such exceptions can be ignored . But this exception usually needs to be named : expected. for example :       6.3
Access to static members : Should pass class , Not the object   When a static member is accessed , Should pass class Name to visit , Instead of using this class Specific instance object of . for example :    
  6.4 Not used Finalizers method   heavy load Object Of finalize Methods are very, very rare .  
be careful : You should not use this method . If you think you have to use , Please read and understand carefully first Effective Java Article 7 “Avoid Finalizers”. Then don't use it .
      Seven ,Javadoc   7.1 Format specification   7.1.1 General format   Basic javadoc The general format of is as follows :     Or in single line format :    
The general format can be used at any time . When javadoc When a block has only one line , You can use a single line format instead of a common format .     7.1.2 paragraph  
Blank line : Means javadoc in , There is only a top-down alignment between the two paragraphs * Line of characters . The first line of each paragraph precedes the first character , There is one <p> label , And there's no space after that .    
7.1.3 @ a clause  
All standard @ a clause , It should be added in the following order :@param,@return,@throws,@deprecated. And these four @ a clause , It shouldn't be in a situation where there's no description Javadoc In blocks .
When @ A clause cannot be written at the end of a line , It should be broken . On the first line @ Character position , Indent at least 4 Character units .     7.2 Summary snippet  
For each class or member javadoc, It's all started with a summary segment . This clip is very important . Because it is the only text description that can be seen when a class or method is used .
The main summary is just a fragment , It should be a noun phrase or a verb phrase , It should not be a complete sentence . But it should use punctuation like a complete sentence .  
be careful : A common mistake is to use it in this way javadoc:/** @return the customer ID */. It's not right . Should be changed to :/** Returns
the customer ID. */.     7.3 Where to use Javadoc  
at least ,Javadoc Should be applied to all public class ,public and protected Member variables and methods for . And a few exceptions . The exceptions are as follows .     7.3.1
exception : Method itself   When the method itself is obvious , No need javadoc. for example :getFoo. No need to add javadoc explain “Returns
the foo”. Methods in unit test can basically pass the method name , It is obvious to know the function of the method . So there is no need to add javadoc.  
be careful : Sometimes this exception should not be quoted , To omit some information that users need to know . for example :getCannicalName . When most code readers don't know canonical
name What do you mean , Should not be omitted Javadoc, Think you can only write /** Returns the canonical name. */ .     7.3.2
exception : Overloading methods   Overloaded methods sometimes don't need to be written again Javadoc.     7.3.3 exception : Optional javadoc  
Some are not visible outside the package class And member variables or methods , As needed , It can also be used javadoc. When a comment is used to describe this class , When the overall goal or behavior of a variable or method , have access to Javadoc.

©2019-2020 Toolsou All rights reserved,
TP6 Application examples of verifier and correct verification data ESP8266/ESP32 System : Optimize system startup time 2021 year 2 Chinese programming language ranking 2021 year 1 Monthly programmer salary statistics , average 14915 element CSS architecture design It's not depravity that's terrible , It's about knowing you're falling Gude Haowen serial - You deserve to be an engineer ( Preface ) Software testing BUG describe C Course design of language programming of 《 Student achievement management system 》vue In the project axios Global encapsulation of