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

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、編輯編輯pptLishoulin,PTC普聯(lián)軟件普聯(lián)軟件(中國中國)有限公司有限公司2011年度入職培訓,濟南燕山學院年度入職培訓,濟南燕山學院PANSOFTJULY,2011編碼規(guī)范編碼規(guī)范(JAVA版版)JAVA之路之路JAVA開發(fā)人員編碼規(guī)范開發(fā)人員編碼規(guī)范Technology Team Progress編輯編輯ppt編輯編輯ppt編輯編輯ppt編輯編輯ppt編輯編輯ppt編輯編輯pptcom.pansoft.public class JRaster;class JImageSprite interface IRasterDelegate;interface IStoring; 編輯編輯

2、pptrun();runFast();getBackground(); 編輯編輯pptchar c;int i;float myWidth; 編輯編輯pptint mEmployeeId;String mName;Customer mCustomer; 編輯編輯pptpublic void callMe(int pAge, String pName)編輯編輯pptstatic final int MIN_WIDTH = 4;static final int MAX_WIDTH = 999;static final int GET_THE_CPU = 1; 編輯編輯ppt/* * Classna

3、me * * Version information * * Date * * Copyright notice */編輯編輯ppt package java.awt; import java.awt.peer.CanvasPeer; 編輯編輯ppt編輯編輯ppt編輯編輯ppt編輯編輯ppt編輯編輯ppt編輯編輯ppt編輯編輯ppt編輯編輯ppt編輯編輯ppt /正常斷行 someMethod(int anArg, Object anotherArg, String yetAnotherArg, Object andStillAnother) . /若斷行后很靠右,則下面行可以縮進8個空格,看

4、上去更美 觀。 private static synchronized horkingLongMethodName(int anArg, Object anotherArg, String yetAnotherArg, Object andStillAnother) . 編輯編輯ppt /縮小過少,不易閱讀1 if (condition1 & condition2)2 | (condition3 & condition4)3 |!(condition5 & condition6) 4 doSomethingAboutIt(); /這一行不易閱讀識別 /較多的縮進,便于閱

5、讀5 if (condition1 & condition2)6 | (condition3 & condition4)7 |!(condition5 & condition6) 8 doSomethingAboutIt(); 編輯編輯ppt1 alpha = (aLongBooleanExpression) ? beta : gamma;2 alpha = (aLongBooleanExpression) ? beta : gamma;3 alpha = (aLongBooleanExpression) ? beta : gamma;編輯編輯ppt編輯編輯ppt編輯編

6、輯ppt /* * Here is a block comment. */編輯編輯ppt1 if (condition) 2 /* Handle the condition. */3 /code.4 編輯編輯ppt1 if (a = 2) 2 return TRUE; /* special case */3 else 4 return isPrime(a); /* works only for odd a */5 編輯編輯ppt1 if (foo 1) 2. / Do a double-flip.3 4 else 5. return false; / Explain why here.6 7.

7、 /if (bar 1) 8 / / Do a triple-flip.9 /10 /else 11 / return false;12 /編輯編輯ppt /* * The Example class provides . */ public class Example .編輯編輯ppt1 int level; / indentation level int size; / size of table /這樣不好 3 int level, size; 4 int foo, fooarray; /錯誤寫法錯誤寫法編輯編輯ppt編輯編輯ppt1 void myMethod() 2 int int1

8、 = 0; / 好的聲明3 if (condition) 4 int int2 = 0; / 不好的聲時5 .6 7 編輯編輯ppt1 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 編輯編輯ppt 1 argv+; / Correct 2 argc-; / Correct 3 argv+; argc-; / AVOID!編輯編輯ppt 1 if ( this.isExist(“0001”)

9、 2 argc-; / Correct 3 System.out.println(“HELLO”); 4 編輯編輯ppt 1. return; 2. return myDisk.size(); 3. return (size ? size : defaultSize);編輯編輯ppt 1. if (condition) 2 statements; 3 4 if (condition) 5 statements; 6 else 7 statements; 8 9 If (condition) 10 statements;11 else if (condition) 12 statements;

10、13 else 14 statements; 15 編輯編輯ppt if (condition) /非法的,應該以包括 statement; 編輯編輯ppt for (initialization; condition; update) statements; 編輯編輯ppt while (condition) statements; while (condition) ;編輯編輯ppt do statements; while (condition);編輯編輯ppt1 switch (condition) 2 case ABC:3 statements;4 /* falls through

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

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

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

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

15、lue(SqlText,),IE.getResultMessage(); /根據(jù)需要,返回對象類型的結果。4 RO.ResponseObject = IE;5 catch (Exception E) /發(fā)生異常時,要把異常信息返回。6 RO.ErrorCode = -1;7 RO.ErrorString = E.getMessage();8 9 finally /finally里執(zhí)行連接的關閉操作。10 conn.close();11 12 return RO;編輯編輯ppt1 Statement pSession = null;2 ResultSet pRS = null;3 pSessio

16、n = conn. createStatement();4 String 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 /這里是一個異常,需要把異常信息想法通知調用者。可以使用throw 拋出。13 編輯編輯ppt 1 finally 2 try 3 /清理操作。 4 if ( pRS != null ) 5 pRS.close(); 6 7 if

17、 ( pSession != null ) 8 pSession.close(); 9 10 11 catch(Exception EE) 12 /這里可能也有異常,不需要拋出。 13 14 編輯編輯ppt編輯編輯ppt編輯編輯ppt編輯編輯ppt 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,Ac

18、tionEvent pEvt) 5 return true; /這里即是處理代碼。 6 7 JMenuItem pMM = new JMenuItem(); 8 pMM.setAction(mActStop);編輯編輯ppt編輯編輯ppt編輯編輯ppt編輯編輯ppt1 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 P1,String P2,String

溫馨提示

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

評論

0/150

提交評論