在线现看午夜福利片|女人16久久免费视频|鲁丝片一区鲁丝片二区鲁丝|一区二区三区欧美在线

  1. 
    
    <b id="glvx9"></b>
        1. <blockquote id="glvx9"><meter id="glvx9"></meter></blockquote>
            首頁(yè) 考試吧論壇 Exam8視線(xiàn) 考試商城 網(wǎng)絡(luò)課程 面授課程 模擬考試 實(shí)用文檔 繽紛校園 英語(yǔ)學(xué)習(xí)
            2010考研 | 自學(xué)考試 | 成人高考 | 專(zhuān) 升 本 | 法律碩士 | MBA/MPA | 中 科 院
            四六級(jí) | 商務(wù)英語(yǔ) | 公共英語(yǔ) | 職稱(chēng)日語(yǔ) | 職稱(chēng)英語(yǔ) | 博思 | 口譯筆譯 | GRE GMAT | 日語(yǔ) | 托福
            雅思 | 專(zhuān)四專(zhuān)八 | 新概念 | 自考英語(yǔ) | 零起點(diǎn)英、、韓語(yǔ) | 在職申碩英語(yǔ)
            在職攻碩英語(yǔ) | 成人英語(yǔ)三級(jí)
            等級(jí)考試 | 水平考試 | 微軟認(rèn)證 | 思科認(rèn)證 | Oracle認(rèn)證 | Linux認(rèn)證
            公務(wù)員 | 報(bào)關(guān)員 | 報(bào)檢員 | 外銷(xiāo)員 | 司法考試 | 導(dǎo)游考試 | 教師資格 | 國(guó)際商務(wù)師 | 跟單員
            單證員 | 物流師 | 價(jià)格鑒證師 | 銀行從業(yè)資格 | 證券從業(yè)資格 | 人力資源管理師 | 管理咨詢(xún)師
            期貨從業(yè)資格 | 社會(huì)工作者
            會(huì)計(jì)職稱(chēng) | 注會(huì)CPA | 經(jīng)濟(jì)師 | 統(tǒng)計(jì)師 | 注冊(cè)稅務(wù)師 | 評(píng)估師 | 精算師 | 高會(huì) | ACCA | 審計(jì)師
            法律顧問(wèn) | 會(huì)計(jì)證
            建造師一級(jí)、二級(jí)) | 造價(jià)師 | 監(jiān)理師 | 安全師 | 咨詢(xún)師 | 結(jié)構(gòu)師 | 建筑師 | 安全評(píng)價(jià)師
            估價(jià)師房地產(chǎn)估價(jià)、土地估價(jià)) | 設(shè)備監(jiān)理師 | 巖土工程師 | 質(zhì)量資格 | 房地產(chǎn)經(jīng)紀(jì)人 | 造價(jià)員
            投資項(xiàng)目管理 | 土地代理人 | 環(huán)保師 | 環(huán)境影響評(píng)價(jià) | 物業(yè)管理師 | 城市規(guī)劃師 | 公路監(jiān)理師
            公路造價(jià)工程師 | 招標(biāo)師
            執(zhí)業(yè)護(hù)士 | 執(zhí)業(yè)醫(yī)師 | 執(zhí)業(yè)藥師 | 衛(wèi)生資格
             丹丹云 
            您現(xiàn)在的位置: 考試吧(Exam8.com) > 軟件水平考試 > 心得技巧 > 正文

            JAVA的編程風(fēng)格

             
               有時(shí)我們會(huì)希望在表達(dá)式中使用表達(dá)式(比如條件嵌套),這時(shí)應(yīng)注意else表達(dá)式,它的位置很容易出錯(cuò)!如例:

            代碼:

            if (expr1) {
              statement1;
              statement2;
            } else if (expr2)
              statement3;
            else if (expr3) {
              statement4;
              statement5;
            } else {
              statement6;
              statement7;
            }


                注意大括號(hào)位置!

                Loops
                while-loop語(yǔ)法如下:

            代碼:

            while (expr) {
              statement1;
              statement2;
            }


                for-loop語(yǔ)法如下:

            代碼:

            for (expr1; expr2; expr3){
              statement1;
              statement2;
            }


                注意大括號(hào)位置!僅一條聲明時(shí)大括號(hào)省略:

            代碼:

            while (expr)
              statement;

            for (expr1; expr2; expr3)
              statement;



                例如,我們寫(xiě)一個(gè)procedure寫(xiě)出1到10這十個(gè)數(shù)字:

            代碼:

            for (i = 1; i <= 10; i++)
              System.out.println(i);



                try-catch語(yǔ)法形如:

            代碼:

            try {
               statements;
            } catch (ExceptionClass e) {
               statements;
            }


                如果try-catch語(yǔ)句后跟隨finally子句則形如:

            代碼:

            try {
               statements;
            } catch (ExceptionClass e) {
               statements;
            } finally {
               statements;
            }



                新行

                每一行最好只闡述一件事情。比如,一行包含一個(gè)聲明、一個(gè)條件語(yǔ)句、一個(gè)循環(huán)等。不論多小,最好不要一行辦兩件事及以上。例如不要把一個(gè)if表達(dá)式或循環(huán)語(yǔ)句的主體放置在同一行,這樣的表達(dá)式斷行的易讀性會(huì)更高。通常,互相協(xié)作的代碼應(yīng)放在一起,為保證代碼美觀(guān)可讀,我們應(yīng)將代碼的不同代碼段放置在不同的段落。不過(guò)要牢記斷行不要太過(guò)分!比如:

            代碼:

            public int factorial(int n) {
             int result = 1;
             for(int i = 1; i <= n; i++)
               result*=i;

             return result;
            }


                給自己的代碼加入注釋

                注釋就是類(lèi)的描繪、方法存在的原因、它完成了什么以及它對(duì)它其中(變量)的作用域。假定閱讀你代碼的人已經(jīng)知道這是什么語(yǔ)言,所以不需要注釋語(yǔ)句功能,盡量使用簡(jiǎn)短而有描述力的注釋。

                Java有兩種類(lèi)型的注釋?zhuān)?

            //This is a comment that continues until the end of the line.

            /* This is a comment. It goes on and on and on and on and on and on and on
            and on and on and on and on and on and on and on and on and on and on and
            on and on and on and on and on and on and on and on and ends like this: */

            /**
            * This is a JavaDoc comment. More about JavaDoc in the next section.
            */


                 如果在注釋中加入注釋則會(huì)出錯(cuò):

            /* You are not allowed to do anything like this /* because the compiler will
              complain, if you are lucky */ DON'T DO THIS! And don't write comments in
              upper case either... */

                注釋?xiě)?yīng)放在它要解釋內(nèi)容上下,這樣會(huì)讓代碼更易于理解。

                不要注釋一些語(yǔ)言的語(yǔ)句功能:
                i++;  // Add 1 to i

                更不要讓自己的代碼處于這種狀態(tài):

            for(int i = 1; i <= n; i++)
              /* don't place comments where  
                 they don't belong */
              result*=i;

                較短的注釋既可被放在被注釋代碼上下,而長(zhǎng)注釋則習(xí)慣性的放在代碼之上:

            /* Comments can be placed before the
              block that is to be commented */
               
            for(int i = 1; i <= n; i++)
             result*=i;

                或者:
            for(int i = 1; i <= n; i++){
             result*=i;                 // short comments can be placed like this
             tmp++;                    // if necessary, they continue here
            }

               不要寫(xiě)沒(méi)用的注釋?zhuān)?

            i++;   // change this later

            Excuse me,這句肯定是胡扯!

                不要寫(xiě)自己都看不懂的注釋?zhuān)?

            i++;  // BMW

                BMW? 如果你能連續(xù)十天記住這是什么意思的話(huà),那么你的記憶真是不錯(cuò)了。所以不要寫(xiě)沒(méi)人能看懂的注釋?zhuān)琽k?

                最后重申一下:寫(xiě)簡(jiǎn)短而富于描述性的注釋?zhuān)阉鼈兎旁谠摲诺牡胤,而不要考?yàn)?zāi)阕约旱挠洃浟Γ?


                JavaDoc - 文檔工具

                JavaDoc不僅是另一種給代碼加注釋的仿佛咱,更是一個(gè)文檔工具。類(lèi)、方法和一些重要地方需要用JavaDoc來(lái)注釋。這并不是說(shuō)你可以放棄常規(guī)的注釋?zhuān)@兩者在代碼中應(yīng)該是相輔相成、互相彌補(bǔ)的關(guān)系。

                類(lèi)被注釋如:

            /**
            * Car represents cars ... A description of the class
            * should be place here. Note that the description begins
            * on the second line and that there is a space between
            * the asterix and the text. Next we will add some fields
            * indicating who the authors of the class are and
            * other useful information. Notice the newline!
            *
            * @author Jerry Meng
            * @version %I%, %G%
            */
            public class Car {

                注意JavaDoc結(jié)束和類(lèi)開(kāi)始間無(wú)空行。 

                方法被注釋如:

            /**
            * A description of what the method does...
            *
            * @param n  a description of the parameter
            * @return   a description of the return value
            */
            public int factorial(int n) {


                某些不是全部,被JavaDoc注釋區(qū)域如:

            /**
            * Short description of the variable (one line)
            */
            type variable; 

            轉(zhuǎn)帖于:軟件水平考試_考試吧
            文章搜索
            JAVA的編程風(fēng)格網(wǎng)友評(píng)論網(wǎng)友評(píng)論
            版權(quán)聲明 --------------------------------------------------------------------------------------
                如果軟件水平考試網(wǎng)所轉(zhuǎn)載內(nèi)容不慎侵犯了您的權(quán)益,請(qǐng)與我們聯(lián)系,我們將會(huì)及時(shí)處理。如轉(zhuǎn)載本軟件水平考試網(wǎng)內(nèi)容,請(qǐng)注明出處。