JAVA編碼規(guī)范(開發(fā)培訓(xùn)講義)ppt課件_第1頁
JAVA編碼規(guī)范(開發(fā)培訓(xùn)講義)ppt課件_第2頁
JAVA編碼規(guī)范(開發(fā)培訓(xùn)講義)ppt課件_第3頁
JAVA編碼規(guī)范(開發(fā)培訓(xùn)講義)ppt課件_第4頁
JAVA編碼規(guī)范(開發(fā)培訓(xùn)講義)ppt課件_第5頁
已閱讀5頁,還剩65頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、Lishoulin,PTC普聯(lián)軟件(中國)2011PANSOFTJULY,2011編碼規(guī)范(JAVA版)JAVA之路JAVA開發(fā)人員編碼規(guī)范Technology Team Progress1;.234567com.pansoft.financecom.pansoft.public class JRaster;class JImageSprite interface IRasterDelegate;interface IStoring; 8run();runFast();getBackground(); 9char c;int i;float myWidth; 10int mEmployeeId

2、;String mName;Customer mCustomer; 11public void callMe(int pAge, String pName)12static final int MIN_WIDTH = 4;static final int MAX_WIDTH = 999;static final int GET_THE_CPU = 1; 13/* * Classname * * Version information * * Date * * Copyright notice */14 package java.awt; import java.awt.peer.CanvasP

3、eer; 151617181920212223 /正常斷行 someMethod(int anArg, Object anotherArg, String yetAnotherArg, Object andStillAnother) . /若斷行后很靠右,則下面行可以縮進(jìn)8個(gè)空格,看上去更美 觀。 private static synchronized horkingLongMethodName(int anArg, Object anotherArg, String yetAnotherArg, Object andStillAnother) . 24 /縮小過少,不易閱讀1 if (con

4、dition1 & condition2)2 | (condition3 & condition4)3 |!(condition5 & condition6) 4 doSomethingAboutIt(); /這一行不易閱讀識(shí)別 /較多的縮進(jìn),便于閱讀5 if (condition1 & condition2)6 | (condition3 & condition4)7 |!(condition5 & condition6) 8 doSomethingAboutIt(); 251 alpha = (aLongBooleanExpression)

5、? beta : gamma;2 alpha = (aLongBooleanExpression) ? beta : gamma;3 alpha = (aLongBooleanExpression) ? beta : gamma;262728 /* * Here is a block comment. */291 if (condition) 2 /* Handle the condition. */3 /code.4 301 if (a = 2) 2 return TRUE; /* special case */3 else 4 return isPrime(a); /* works onl

6、y for odd a */5 311 if (foo 1) 2. / Do a double-flip.3 4 else 5. return false; / Explain why here.6 7. /if (bar 1) 8 / / Do a triple-flip.9 /10 /else 11 / return false;12 /32 /* * The Example class provides . */ public class Example .331 int level; / indentation level int size; / size of table /這樣不好

7、 3 int level, size; 4 int foo, fooarray; /錯(cuò)誤寫法錯(cuò)誤寫法34351 void myMethod() 2 int int1 = 0; / 好的聲明3 if (condition) 4 int int2 = 0; / 不好的聲時(shí)5 .6 7 361 class Sample extends Object 2 int ivar1;3 int ivar2;4 Sample(int i, int j) 5 ivar1 = i;6 ivar2 = j;7 8 int emptyMethod() 9 .10 37 1 argv+; / Correct 2 argc

8、-; / Correct 3 argv+; argc-; / AVOID!38 1 if ( this.isExist(“0001”) 2 argc-; / Correct 3 System.out.println(“HELLO”); 4 39 1. return; 2. return myDisk.size(); 3. return (size ? size : defaultSize);40 1. if (condition) 2 statements; 3 4 if (condition) 5 statements; 6 else 7 statements; 8 9 If (condit

9、ion) 10 statements;11 else if (condition) 12 statements; 13 else 14 statements; 15 41 if (condition) /非法的,應(yīng)該以包括 statement; 42 for (initialization; condition; update) statements; 43 while (condition) statements; while (condition) ;44 do statements; while (condition);451 switch (condition) 2 case ABC:

10、3 statements;4 /* falls through */5 case DEF:6 statements;7 break;8 case XYZ:9 statements;10 break;11 default:12 statements;13 break;14 46 try statements; catch (ExceptionClass e) statements; finally statements; 4748491 a += c + d;2 a = (a + b) / (c * d);3 while (d+ = s+) 4 n+;5 6 printSize(size is

11、+ foo + n); 7 for (expr1; expr2; expr3)8 myMethod(byte) aNum, (Object) x);9 myMethod(int) (cp + 5), (int) (i + 3) + 1);50 1 ooBar.fChar = barFoo.lchar = c; / 禁止此種方法 2 if (c+ = d+) / AVOID! (Java disallows) . 3 /應(yīng)該寫成 4 if (c+ = d+) != 0) . 5 51 1 d = (a = b + c) + r; / AVOID /應(yīng)該寫成 2 a = b + c; 3 d =

12、a + r;521 if (booleanExpression) 2 return true;3 else 4 return false;5 應(yīng)該代之以如下方法:6 return booleanExpression;1 if (condition) 2 return x;3 4 return y; 應(yīng)該寫做:5 return (condition ? x : y);535455561 JResponseObject RO = new JResponseObject();/獲得一個(gè)可用連接,這個(gè)連接可能獲取不到。2 JConnection conn = 3 (JConnection) JActi

13、veDComDM.AbstractDataActiveFramework.InvokeObjectMethod(4 DBManagerObject, GetDBConnection, Param);/因此,這里要判斷一下。5 if ( conn = null ) /如果是無效連接,要返回錯(cuò)誤信息。6 RO.ErrorCode = -1;7 RO.ErrorString = 無法獲得數(shù)據(jù)庫連接;8 return RO;9 571 try 2 DBOFormService.3 SQLQuery(conn,msgInput.asStringValue(SqlText,),IE.getResultMe

14、ssage(); /根據(jù)需要,返回對(duì)象類型的結(jié)果。4 RO.ResponseObject = IE;5 catch (Exception E) /發(fā)生異常時(shí),要把異常信息返回。6 RO.ErrorCode = -1;7 RO.ErrorString = E.getMessage();8 9 finally /finally里執(zhí)行連接的關(guān)閉操作。10 conn.close();11 12 return RO;581 Statement pSession = null;2 ResultSet pRS = null;3 pSession = conn. createStatement();4 Str

15、ing pSql = “SELECT * FROM LSCONF WHERE 1 = 1 ”;5 try6 pRS = pSession. executeQuery (pSql);7 if ( pRS.next()8 /這里是邏輯代碼。用來取數(shù)。9 10 11 catch(Exception E)12 /這里是一個(gè)異常,需要把異常信息想法通知調(diào)用者??梢允褂胻hrow 拋出。13 59 1 finally 2 try 3 /清理操作。 4 if ( pRS != null ) 5 pRS.close(); 6 7 if ( pSession != null ) 8 pSession.close

16、(); 9 10 11 catch(Exception EE) 12 /這里可能也有異常,不需要拋出。 13 14 60616263 1 IAction mActStop = TAction.Create(STOP, 停止,S,this,onStop,SYS_STOP); 2 JButton btStop = new JButton(“”); 3 btStop.setAction(mActStop); 4 public boolean onStop(IAction pAct,ActionEvent pEvt) 5 return true; /這里即是處理代碼。 6 7 JMenuItem pM

17、M = new JMenuItem(); 8 pMM.setAction(mActStop);646566671 public static String F(String pStringFormat,String P1)2 public static String F(String pStringFormat,String P1,String P2)3 public static String F(String pStringFormat,String P1,String P2,String P3)4 public static String F(String pStringFormat,String

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論