Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java development specifications summary     - CentOS7 virtual machine creation failed Solution (Linux)

- Linux smart small switch rfkill (Linux)

- DB2 table space is redirected to restore the database combat (Database)

- Linux SU command security Suggestions (Linux)

- Python system default encoding (Programming)

- Ubuntu 14.10 used ifconfig commands to manage your network configuration (Linux)

- Installation on Ubuntu class Winamp audio player Qmmp 0.9.0 (Linux)

- Linux5.8 installed phpMyAdmin was unable to issue related php-mcrypt (Database)

- Iptables on the request URL for IP access control (Linux)

- CentOS / Linux kernel upgrade (Linux)

- How to migrate MySQL to MariaDB under linux (Database)

- Oracle 11g RMAN virtual private directory (Database)

- Two classic macro definition under Linux (Linux)

- Some common regular expressions (Linux)

- Encrypted with GnuPG signature to verify the authenticity and integrity of downloaded file (Linux)

- The wrong in Linux: too many open files (Linux)

- Use Linux built-in firewall to improve network access control (Linux)

- Camera-based face recognition OpenCV crawl and storage format (Python) (Linux)

- Default permissions Linux file and directory permissions and hide - umask, chattr, lsattr, SUID, SGID, SBIT, file (Linux)

- Java Prototype Pattern (Programming)

 
         
  Java development specifications summary
     
  Add Date : 2017-09-18      
         
       
         
  Specification requires attention encoding process usually is a good habit slowly

1. The basic rule

   1. Comments should make the code more clear and understandable
   2. Note should be simple and clear, as long as the program can be clearly understood that the information necessary for it. If a comment is too complex instructions need to be modified to adjust the program to make the design more reasonable.
   3. Notes program not only describes what has been done, but also to describe why, and constraints
   4. For the average getter, setter methods without comment
   5. The comments can not be nested
   6. The need to generate documents written in Chinese development

2. The three kinds of comments by way of illustration

   1. Documentation comments / ** * /

      Can use multiple lines, generally used for classes, interfaces, member methods, member variables, static fields, static methods, constants will be described. Javadoc can use it to produce the document code. For readability, you can have indented and format control.
      Doc comments describe some specific purposes often used tags documentation to help generate Javadoc documentation, commonly used are:

label

Used for

purpose

@author name

Class / Interface

Description Code authors, each author corresponds to one such label

@deprecated

class

Member method

Description of the API section has been repealed

@exception name description

  or

  @throws name description

Member method

Describes an exception thrown

Each anomaly is a corresponding one such label

@param name description

Member method

Member method described in the use and meaning of the parameters, a parameter corresponding to such a label

@return description

Member method

Meaning the return value of the method described members

@since

Class / Interface

Member method

API describing the segment start time

@see ClassName

Class / Interface

Member method

Member variables

It used to refer to a particular class description, including the full name with the general ClassName package names

@see ClassName # memberfunction

Class / Interface

Member method

Member variables

It used to refer to members of the class to describe specific methods generally include the full name ClassName with the package name

@version text

Class / Interface

version

@inheritDoc

Class / Interface

Member method

Inherited document

   2. line comment //

      You can only comment line, generally used to describe a brief one local variable, block effect

   3. Block comments: / * * /

      It prohibits the use of code

   4. Class / Interface comment

       Class / interface description, tend to be more detailed. According to the usual order of the instructions, including
          1. The main class to. Or. End
          2. Class design goal, to complete what kind of function
          3. < Strong> main classes use < / Strong> How to use this class, including environmental requirements, such as whether thread safety, concurrency requirements, and the use of restraint
          4. < Strong> known BUG < / Strong>
          5. Describe the modification history class: < Strong> Modifier + date + Brief Description < / Strong>
          OF 6. @ author, @ version version, @see reference, @ since the beginning of the version and other information such as:

/ **
 * This class provides default implementations for the JFC < code> Action < / code>
 * Interface. Standard behaviors like the get and set methods for
 * < Code> Action < / code> object properties (icon, text, and enabled) are defined
 * Here. The developer need only subclass this abstract class and
 * Define the < code> actionPerformed < / code> method.
 * < P>
 * < Strong> Warning: < / strong>
 * Serialized objects of this class will not be compatible with
 * Future Swing releases. The current serialization support is appropriate
 * For short term storage or RMI between applications running the same
 * Version of Swing. A future release of Swing will provide support for
 * Long term persistence.
 *
 * @version 1.41 2015/05/26
 * @author Xxxxx
 * @see Action
 * /
      In order to make the document readable form good, indents, and often with the format control comments. Class described in the immediately preceding class of the class definition, can not have any blank lines.

3. The variable comment

     1. member variables, static class variables using documentation comments, the comments of the member variables usually include:
        1) Significance of the variables
        Legal range 2) variable
        3) restrictions on concurrent access
         Such as:

 / **
* Web.xml file configServlet parameters UIAPP.xml initparam
 * /
    public final static String APP_CONFIG = "aaa.uiapp";
    2. Local variables, such as variables related to the algorithm using block or line comments

public void func () {
    int i; // for loop count
    ............
}
   3. Parameter variable comment ships with documentation comments, and using @param described as parameters generally include

       1) the use of parameters

       2) the requirements for the range of parameter values

4. Method Comment

   Function Description function of member methods, static methods commonly used document describes, in particular, the method disclosed. Comments can be very detailed, highly readable also be included in order to control the format, as explained below contains indent:

/ **
* Here is a method comment with some very special
* Formatting that I want indent (1) to ignore. *

* /
    NOTE method generally includes:
        1. The main method to. Or. End
        What kind of target function, method 2. Describe the method completes, the reasons for using this method
        3. Describe the use of methods, including the use of environmental requirements, such as pre-conditions, post-conditions and concurrency requirements
        4. Describe the known bug
        5. Describe the method of modification history: < Strong> Modifier + date + Brief Description < / Strong> (< Modifier + date + Brief Description>)
        6. @ param c elements to be inserted into this list. (Parameter)
        7. @ return < tt> true < / tt> if this list changed as a result of the call. (Return Value)
        8. @ throws NullPointerException if the specified Collection is null. (Exception description)
        9. @ see if overloaded method must refer to the parent class method
       10Eclips using Alt + Shift + J to generate Javadoc description of the method back value ((@return below)

5. Modify record

    1. Modify a class before, we must start with the SVN update, after further modification;
    2. Modify the place must be added a note about modifying people, reasons for the revisions, modifications, modification time;

Specification requires attention encoding process usually is a good habit slowly

1. Basic Principles

   Mandatory principles:
     1. String fight plus, you must use StringBuilder;
     2.try ... catch Usage

 
try {

} Catch {Exception e
    e.printStackTrace ();
} Finally {

} // Outermost Action can be used in other places will be prohibited;
 
try {
    //code
} Catch (Exception e) {
    // Empty, nothing to write
} // In any scene are prohibited
 
try {

} Catch {Exception e
    throw new runtimeException (e); // the priority use wording
} Finally {

}
     1. For after capture, do not know what to do or do not know how to deal with the situation, do not catch the exception, leaving out layers to capture process;
     2. The return type is set, you must use a generic method declaration must indicate what happens next in the javadoc return null, return empty under what circumstances.
     3. For the method to be used as a variable declaration scope priority: private, protected, public, for the variables to be used as a priority: In local variables, instance variables, class variables, if you have to use an instance variable or class variable case to ensure thread safety, if possible, to save as much as possible the use of ThreadLocal instance variables or class variables;
     4. If it is not necessary, not to define new variables or objects in a loop; as far as needed to the last minute before going to new objects;
     5. If it is not necessary, do not go cycling with a try ... catch;
     6. classes for more complex logic by way of line comments to annotate, java code and definitely not use block comments (/ ** /) to annotate;
     Name of the first picture 7.Java class must be capitalized, have multiple-word, capitalize the first letter of each word
     8.jsp file name must be all lowercase;
     9.Spring the bean configuration file name must be lowercase format xxx.bean.xml, xxx.bean.xml configuration file < bean id = "", id here, is the first letter lowercase class name put here.
    10.xwork profile name must be lowercase, and follow xwork_xxx.xml format of writing, where XXX is an abbreviation for the name of the business;
   11. The processing of the log,

if (log.isDebugEnabled ())
ex.printStackTrace ();
else
log.error ( "deleted from the database: [" + entity.getClass () getName () +. "] Examples of failure", daex);
throw new PersistenceException ( "deleted from the database: [" + entity.getClass () getName () +. "] Examples of failure", daex);
    12. Do not use the code System.out.println () debugging output debug information if you want to use, you must use log.debug (). For the necessary information to use log.info () output;
    13. The classes do not appear useless import, IDE tools can be used to optimize the formatting codes before class submitted;
    14. Class of business logic must write junit unit test classes;
    15. The international support: ftl templates allowed Chinese characters to put all the appropriate properties file, file properties and Action classes to put in the same directory; ftl encoding to UTF-8 format used in all the ; named properties file: Chinese: Action name + "_ zh" + "_ CN" .properties, English: Action name + "_ en" + "_ US" .properties
    16. a program file should not exceed 2000 lines
    17. as far as possible to narrow the scope of the object, the visible range and the survival of this object will also as small as possible and do all possible priority to local variables, there is no way to use global variables, using ThreadLocal priority to deal with.
    18. A method performed by a single function to different functions for different packaging methods.
    19. The possible exceptions, or translation exception, not blindly wrapped exception
    20. If the object must be cleaned up within a specific range (instead of as garbage is recycled), use a try block with a finally clause, clean finally clause.
    21. For some logically related classes grouped together, consider the definition of a class defined in another class in this case it is recommended to use the internal class (such as the interface layer incident response, etc.). Inner class has access to all members of the class of all peripherals.
    22. Access to member variables preferably through getter / setter methods, which can ensure the legitimacy of access and code tuning
    23. The preferred interface rather than abstract or concrete classes. If you know something will be the base class, you priority should be designed to interface to them; only have to put in method definitions or member variables, and only then change it to concrete or abstract class. And customer interface only hope of action relating to (the agreement), and we tend to focus on the implementation details of the class.
    24. The use of the container java standard library. Proficient in their use, will greatly improve efficiency. ArrayList preference to processing sequence structure, selection HashSet to handle collection, select HashMap to handle associative arrays, select linkedList to process stacks and queues, it is optimized for sequential access, small to middle List insertion and deletion overhead, but random access it is slower. When using the front three, when they should be up transition to List, Set, and Map, so you can when necessary in other ways
    25. An array is a most efficient random access memory and object reference sequence mode, but when you create an array object, the size of the array is fixed, and if we create a new array when the lack of space for replication, so efficiency it is larger than the cost of the ArrayList. You must explicitly use scenarios.
    26. Try to use "private", "protected" keywords. Once you put the signature database (including classes, methods, fields) marked as public, you'll no longer possible to remove them. In this manner, the impact of changes implemented in the derived class to cause minimal, when dealing with multi-threading issues, maintaining privacy is especially important, because only Private fields will be protected, without fear of being unaffected of synchronization control use damaged.
    27. Prohibition background business code to use the following code

try {
    something ()
} Catch (Exception ex)
{}
new Exception ()
2. Class preparation of specifications

   Organizational structure and the like, generally in the following order:
     1. Constant declaration
     2. Static variable declarations
     3. Member variable declaration
     4. Constructor part
     5. Finalize part
     6. Methods members
     7. Static Methods
     8. This order is recommended and may be modified in accordance with a certain scale in the actual development, the principle is the program easier to read. As the importance of sorting methods, or in alphabetical order or arrangement in accordance with the method according to the relationship between.
     9. Each method (including the structure and finalize) is a segment. A plurality of variable declarations logically together form a segment separated between paragraphs with blank lines.
     10. Class of statement, to point out that its access control, generally no modifiers, public, and private.
     11. The method and between methods, we need to isolate the blank line between the large portions.
     12. prepare versatile class, observe the standard form. Including the definition of equals (), hasCode (), toString (), Clone (implement Cloneable interface), and implements the interface Comparable and Serialiable
     13. With regard to inheritance is not required during the design class, try to use the final

3. The variable preparation of specifications

   1. member variables, maximize the use of private
   2. Each variable declaration / definition of one row (except parameter variables), such as

int a;
int b;
        Than int a, b; easier to read, easier to find bug

   3. Local variables must be initialized before use, usually in the initialization statement
   4. To declare a variable position at the beginning of the block

     Such as

public void myMethod () {
  int int1 = 0; // beginning of method block
  if (condition) {
    int int2 = 0; // beginning of "if" block
    ...
  }
}
    An exception is in the for statement, the statement is defined not only one row, the expression is still inside, completely Eclips generation, such as:

for (int i = 0; i < 100; i ++)
    5. Affirms array using < data type [] + variable name> methods such as

char [] buffer;
Instead of

char buffer [];
4. The method of preparation of specifications

    1. member methods, do not easily use public member variables. There are major modifiers public, private, protected, no
    2. The method declarations and empty method body can function on one line. Such as: void func () {}
    3. The blank line between method and method
    4. documentation comments immediately preceding method in the method can not be a blank line.
    5. Avoid excessive parameter list, try to control in less than five, if you need to pass multiple parameters, when an object using a hold of these parameters are passed to improve the readability and scalability
    6. A method of circulating latent cover layer can not exceed 2
    7. For the design does not need to reload during a subclass of class, to make use of final
    8. Each line method as much as possible the number of codes and no more than 100 lines (effective lines of code, not including notes), but must ensure that the integrity of the logic
    9. Interface Method default level is protected, only a confirmation packet other subsystems will call interface methods own subsystem, before the method exposed as public.

5. The use of language and writing specifications

   1. Avoid defining variables of the same name with a layer scoped variables.
   We need to be separated by a blank line between 2. Methods and Techniques
   3. Local variables are declared using the moment, local variables / static variables simultaneously initialized when declared
   4. In comparison with the constant comparison expressions are often placed in front of the number, such as:

if ( "simpleCase" .equals (obj)) ...
if (null == obj) ....
   5.return statement, do not have complex operations.
   6.switch statement requires a default branch
     
         
       
         
  More:      
 
- awk pattern matching (Programming)
- Compile and install LNMP under CentOS 6.5 (Server)
- Linux System Getting Started Learning: Repair (Linux)
- C # socket udp broadcast (Programming)
- Linux processes in memory and memory cgroup statistics (Linux)
- WEB-based Android Remote Tools Python implementation (Programming)
- Jetty JNDI Development combat (Linux)
- Sqoop data export import command (Database)
- TOAD connect DB2 error SQL1460N solve (Database)
- shell script: the number of characters in the text to print no more than 6 words (Programming)
- Install Mac OS X 10.9 systems VMware10 (Linux)
- Analysis of Java keyword final (Programming)
- CentOS7 install JDK (Linux)
- Linux distributed message queue RocketMQ deployment and monitoring - Dual Master (Server)
- MySQL IO SSD attempt at optimization (Database)
- The most concise explanation of JavaScript closures (Programming)
- Iptables on the request URL for IP access control (Linux)
- Using IE can also be easily remotely control the computer (Linux)
- Compiling source code Nginx module installation subs_filter (Server)
- CentOS7 virtual machine starts appear Permission denied (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.