"Reproduced in Http://www.cnblogs.com/hemingwang0902/archive/2012/01/06/2314215.html"
A coding note was written based on some of the problems with the code in the current project. These considerations are based on the code of the project that you are currently implementing, not as a coding specification for the project, but as a reference for project team members only.
1. all source files ( including. Java,. JSP,. Properties,. html,. js, . css,. xml,. txt , etc.) unify the use of UTF-8 encoding.
2. get the latest code from SVN when you go to work every day , and before you leave, you must submit the code of the function module passed by the test to the SVN repository. The code submitted to SVN must be complete!
1. JAVA
1. The naming of classes and methods must be meaningful, and the naming style must be consistent, prohibiting the use of English-Chinese mash-up (as far as possible, rather than Hanyu Pinyin).
2. Prohibit hard-coded , frequently used in the project and in the whole project development, the operation process will never change the value, can be uniformly defined as Java constants in a constant interface, if the project development, the process may need to modify the value (such as database configuration information), You must define it in the configuration file.
3. For I/O Stream objects ,JDBC Operations database Objects ,Socket objects ,LDAP Connection objects ,JMS Connection Objects , and so on, must be closed in the finally block when the use is complete. If declared in the loop body, it must be closed in the body of the loop. (who declares, who manages).
4. Compile-level systems above JDK 1.5, the collection class is recommended to use generics at development time to avoid warnings everywhere in the program.
5. Try to avoid storing large objects in the HTTP session , especially large collection objects.
6. when working with the database through JDBC , it is possible to perform functions through a SQL statement, avoiding the use of multiple SQL to execute separately, and if multiple DML statements are executed at the same time, the transaction must be turned on to ensure the integrity of the data. For operations that need to pass in parameters, to prevent SQL injection, you must use Java.sql.PreparedStatement instead of using Java.sql.Statement.
7. Many classes require a method to be extracted to the *util class as much as possible, rather than being defined once in each class that uses the method, and if only a few of the same types of classes share a method, consider extracting it into the parent class.
8. Commonly used strings , numbers , dates , array operations, you should try to use the method in Apache-commons-lang.jar; common I/O operations, You should try to use the methods in Apache-commons-io.jar instead of defining them yourself.
9. When the servlet or action returns JSON-formatted data, do not manually stitch up the JSON-formatted string, but instead use the related classes in Json-lib.jar directly.
10. System.out.println is forbidden in the program. The statement should be replaced with logger.debug or logger.info; E.printstacktrace (); Logger.warn (e) or Logger.error (e) should be used instead.
11. For code in the//TODO tag statement, after the completion of the task of the code written, should be deleted in a timely manner.
12. If a class has a pair of operations, the name of the method must be aware of the relative, common method naming correspondence is:
Add-->remove, Insert-->delete, Put-->get, Create-->drop, Init-->destroy, Open-->close, start--> Stop, Begin-->end, First-->last, next-->previous, Up-->down, Send-->receive, Lock-->unlock, show-- >hide
2. JSP
1. Parts that are common to multiple pages (such as headers and footers) should be extracted as separate JSP files and then included with <% @taglib inclue ...%> for each page that uses that part of the code.
2. When introducing other JSP files, try to use instruction to introduce, if need dynamic incoming parameter, consider using JSP action to introduce.
3. Can be implemented with EL expression and JSP tag, try to avoid using Java script code such as <%%>.
4. When introducing Java classes into a JSP file, in order to improve the readability of the code, try to take a single row per class.
3. HTML
1. The first line of each HTML page must be a DOCTYPE declaration that tells the browser to parse the CSS pattern so that the page does not appear differently in each browser.
2. Use the DIV layout as much as possible, rather than using table nested table as the page layout.
3. When specifying widths and heights for elements such as table, TD, and so on, you should use styles to specify them instead of using the width and height properties of the elements.
4. The nesting of elements within the page must correspond to one by one.
5. Add a blank area around the contents of the text in the element to prevent the use of And <br> should instead be controlled using the padding style of the element.
4. JavaScript
1. The shared JS fragment must be extracted as a separate method.
2. The common JavaScript method for multiple pages must be extracted as a separate JS file, prohibiting the writing of the same method on each page.
3. The naming of methods and variables must be meaningful and forbidden to be named like AAA or BBB.
4. The method that executes immediately after the page loads completes, avoids using <body onload= "xxx ()" > and Window.onload=function () {} As far as possible, should use JQuery (document) instead. Ready ( function () {}); The form.
5. Try to avoid using both native JS and jQuery to manipulate page elements on the same page or in the same JS file.
5. CSS
1. Styles that are common to multiple pages must be extracted as separate CSS files.
2. The style class names in the CSS file must be meaningful, and names that are similar to STYLE1 and STYLE2 are forbidden.
3. The CSS file aborts using a selector such as a tagName tagName (such as a Div div) and should be changed to a form #id tagName or. Class TagName.
4. Ordering of selectors in CSS files: element selector –> class selector –> ID Selector
Considerations in the work of the Java EE