1. non-null judgment is required for null cases to prevent null exceptions. We recommend that you use apache commons-lang to effectively build NullpointExcetipion and NumberFormrtException.
2. Try not to have multiple entrances and exits in a method. Try to have one portal and one exit, that is, reduce return. 3. Remember to close all streams after the operation, especially during file operations. 4. Try to put objects that cannot be empty before using the equels method. 5. Try your best in judgment! Replace = false to make the code readable. 6. Try not to operate the parameter value in the method to avoid changing the value and affecting the business logic. 7. When using new ArrayList (), try to use the parent class List as much as possible. In this way, it is better to do it during expansion and complies with the dependency reversal principle. 8. Simple judgment: encapsulate public static final Map <Integer, String> printResultMap = new HashMap <Integer, String> (); static {printResultMap. put (1, ResultCodeDefine. DRAW_TICKET_SUCCESS); printResultMap. put (4, ResultCodeDefine. DRAW_TICKET_ERROR); printResultMap. put (0, ResultCodeDefine. DRAW_TICKET_SUCCESS);} 9. Soft encoding. Code like 1 2 3 cannot be defined. We recommend that you unify the configuration into common classes or make them configurable. 10, in the encapsulation of commonly used string date to use aptech help class commons-lang.jar11, clever use of enumeration, to ensure the rigor of the Code, improve readability. Public enum BoMsgStatus {// 0: initialization status // 1: warehouse receiving/2: ticket issuing in progress // 3: ticket issuing successful // 4: ticket issuing failed DEFAULT (short) 0), DB (short) 1), RUN (short) 2), SUCCESS (short) 3), FAILURE (short) 4); private final short value; public short getValue () {return value;} BoMsgStatus (short value) {this. value = value;} public static BoMsgStatus getEnum (short value) {for (BoMsgStatus bms: BoMsgStatus. values () {if (bms. getValue () = value) {return Bms ;}} return null ;}12. The log output format must be adequate and output in a certain format to facilitate later log analysis.
This article is from my site blog, please be sure to keep this source http://zhaoyongpan.blog.51cto.com/2714930/676934