博客

  • Java開發者的堅守的基本原則

    有許多標準和實踐準則可適用於Java開發者,但此處要說的,是每個Java開發者需堅守的基本原則。

      一、為代碼加註釋。雖然每個人都知道這點,但有時卻不自覺忘了履行,今天你“忘了”加註釋了嗎?雖然註釋對程序的功能沒什麼“貢獻”,但過一段時間,比如說兩星期之後或者更長,回過頭來看看自己的代碼,說不定已經記不住它是乾什麼的了。假如這些代碼是你個人的,那還算是走運了,不幸的是,當然了,大多數時候都是別人的不幸,很多時候大家都是在為公司寫代碼,寫代碼的人也許早已經離開了公司,但別忘了一句古話,有來有往嘛,為他人,也為我們自己,請為你的代碼加上註釋。
      二、不要讓事情複雜化。程序員有時候總是對簡單問題想出複雜的解決方案,比如說,在只有五個用戶的程序中引入EJB、對程序實現了並不需要的框架(framework),之類的還有屬性文件、面向對象解決方案、多線程等等。為什麼要這樣做呢?也許我們並不知道是否這樣會更好,但這樣做也許可以學到一些新東西,或者讓自己更感愛好一些。假如是不知道為什麼這樣做,建議多請教經驗豐富的程序員,假如是為了個人的目的,麻煩讓自己更專業一點。
    三、始終牢記——“少即是好(Less is more)並不總是對的”。代碼效率雖然很重要,但在許多解決方案中,編寫更少的代碼並不能改善這些代碼的效率,請看下面這個簡單的例子:
             
                 if(newStatusCode.equals(“SD”) && (sellOffDate == null ||
                todayDate.compareTo(sellOffDate)<0 || (lastUsedDate != null &&
                todayDate.compareTo(lastUsedDate)>0)) ||
                (newStatusCode.equals(“OBS”) && (OBSDate == null ||
                todayDate.compareTo(OBSDate)<0))){
                newStatusCode = “NYP”;
                } 
             
    能看明白if條件語句是乾什麼的嗎?能想出來是誰寫的這段代碼嗎?假如把它分成兩段獨立的if語句,是不是更輕易理解呢,下面是修改後的代碼:
             
                 if(newStatusCode.equals(“SD”) && (sellOffDate == null ||
                todayDate.compareTo(sellOffDate)<0 || (lastUsedDate != null &&
                todayDate.compareTo(lastUsedDate)>0))){
                newStatusCode = “NYP”;
                }else
                if(newStatusCode.equals(“OBS”) && (OBSDate == null ||
                todayDate.compareTo(OBSDate)<0))
                {
                newStatusCode = “NYP”;
                } 
             是不是讀起來輕易多了呢,在此只是多加了一個if和兩個花括號,但代碼的可讀性與可理解性就一下子提高了一大截。
      四、請不要硬編碼。開發者經常有意“忘記”或忽略掉這點,因為有些時候開發日程逼得實在太緊。其實,多寫一行定義靜態變量的代碼能花多少時間呢?
                public class A {
                public static final String S_CONSTANT_ABC = “ABC”;
                public boolean methodA(String sParam1){
                if (A.S_CONSTANT_ABC.equalsIgnoreCase(sParam1)){
                return true;
                }
                return false;
                }
                } 
             

    現在,每次需要將“ABC”與其他變量進行比較時,不必記住實際代碼,直接引用A.S_CONSTANT_ABC就行了,而且在今後需要進行修改時,也可在一處修改,不會翻遍整個源代碼逐個修改了。
    五、不要“創造”自己的框架(framework)。確切來說,有數以千計的各種框架存在,而且大多數是開源的,這些框架都是優秀的解決方案,可用於日常程序開發中,我們只需使用這些框架的最新版本就行了,至少表面上要跟上形勢吧。被大家廣為接受的最為明顯的一個例子就是Struts了,這個開源web框架非常適合用在基於web的應用程序中。是不是想開發出自己的Struts呢,還是省點力氣吧,回頭看看第二條——不要讓事情複雜化。另外,假如正在開發的程序只有3個窗口,就不要使用Struts了,對這種程序來說,不需要那麼多的“控制”。
    六、不要使用println及字符串連接。通常為了調試方便,開發者喜歡在可能的所有地方都加上System.out.println,也許還會提醒自己回過頭來再來刪除,但有些時候,經常會忘了刪除或者不願意刪除它們。既然使用System.out.println是為了測試,那麼測試完之後,為什麼還要留著它們呢,因為在刪除時,很可能會刪除掉真正有用的代碼,所以不能低估System.out.println危害啊,請看下面的代碼:
             
                 public class BadCode {
                public static void calculationWithPrint(){
                double someValue = 0D;
                for (int i = 0; i < 10000; i ) {
                System.out.println(someValue = someValue i);
                }
                }
                public static void calculationWithOutPrint(){
                double someValue = 0D;
                for (int i = 0; i < 10000; i ) {
                someValue = someValue i;
                }
                }
                public static void main(String [] n) {
                BadCode.calculationWithPrint();
                BadCode.calculationWithOutPrint();
                }
                } 
             

    從測試中可以發現,方法calculationWithOutPrint()執行用了0.001204秒,作為對比,方法calculationWithPrint()執行可是用了10.52秒。
    要避免浪費CPU時間,最好的方法是引入像如下的包裝方法:
             
                public class BadCode {
                public static final int DEBUG_MODE = 1;
                public static final int PRODUCTION_MODE = 2;
                public static void calculationWithPrint(int logMode){
                double someValue = 0D;
                for (int i = 0; i < 10000; i ) {
                someValue = someValue i;
                myPrintMethod(logMode, someValue);
                }
                }
                public static void myPrintMethod(int logMode, double value) {
                if (logMode > BadCode.DEBUG_MODE) { return; }
                System.out.println(value);
                }
                public static void main(String [] n) {
                BadCode.calculationWithPrint(BadCode.PRODUCTION_MODE);
                }
                } 

    另外,字符串連接也是浪費CPU時間的一個大頭,請看下面的示例代碼:

                public static void concatenateStrings(String startingString) {
                for (int i = 0; i < 20; i ) {
                startingString = startingString startingString;
                }
                }
                public static void concatenateStringsUsingStringBuffer(String startingString) {
                StringBuffer sb = new StringBuffer();
                sb.append(startingString);
                for (int i = 0; i < 20; i ) {
                sb.append(sb.toString());
                }
                } 
             
        在測試中可發現,使用StringBuffer的方法只用了0.01秒執行完畢,而使用連接的方法則用了0.08秒,選擇顯而易見了。
      七、多關注GUI(用戶界面)。再三強調,GUI對商業客戶來說,與程序的功能及效率同等重要,GUI是一個成功程序的最基本部分,而很多IT經理往往都沒注重到GUI的重要性。在現實生活中,許多公司可能為了節省開支,沒有僱用那些有著設計“用戶友好”界面豐富經驗的網頁設計者,此時Java開發者只能依靠他們自身的HTML基本功及在此領域有限的知識,結果,很多開發出來的程序都是“計算機友好”甚於“用戶友好”。很少有開發者同時精通軟件開發及GUI設計,假如你在公司“不幸”被分配負責程序界面,就應該遵守下面三條原則:
               1、 不要再發明一次輪子,即不做無用功。現有的程序可能會有類似的界面需求。

      2、 先創建一個原型。這是非常重要一步,用戶一般想看到他們將使用的東西,而且可以先利用這個原型徵求用戶的意見,再慢慢修改成用戶想

    要的樣子。
      3、 學會換位思考。換句話來說,就是從用戶的角度來審查程序的需求。舉例來講,一個匯總的窗口可以跨頁或者不跨頁,作為一個軟件開發者,可能會傾向於不跨頁,因為這樣簡單一些。但是,從用戶的角度來看,可能不希望看到上百行數據都擠在同一頁上。
      八、文檔需求不放鬆。每個商業需求都必須記錄在案,這可能聽上去像童話,似乎在現實生活中很難實現。而我們要做的是,不管開發時間多緊迫,不管最終期限多臨近,對每個商業需求都必須記錄在案。
    九、單元測試、單元測試、單元測試。關於什麼是單元測試的最好方法,在此不便細說,只是強調,單元測試一定要完成,這也是編程中最基本的原則。當然了,假如有人幫你做單元測試自然是最好,假如沒有,就自己來做吧,當創建一個單元測試計劃時,請遵守以下三條最基本的原則:
    1、 先於編寫類代碼之前編寫單元測試。
    2、 記錄單元測試中的代碼註釋。
    3、 測試所有執行要害功能的公有方法,這裡不是指set和get方法,除非它們是以自己獨特方式執行set和get方法。
      十、質量,而不是數量。有些時候因為產品問題、期限緊迫、或一些預料之外的事情,導致經常不能按時下班,但一般而言,公司不會因為僱員經常加班而對之表揚和獎勵,公司只看重高質量的工作。假如遵守了前九條原則,你會發現自己寫出的代碼bug少且可維護性高,無形中質量提高了一大步。

  • CIW的考試費用及考試重點

    參加CIW考試須到指定的授權考試中心參加考試,考試費用為135美元/門(各考試機構應該有不同的折算,具體費用考生可諮詢當地考試機構)。
      
    考題數量及重點
    一般情況下,考題數量分配情況是:
      
    “Network Security and Firewalls”有22道考題;
    “Operating Systems security”有16道考題;
    “Security Auditing, Attacks and Threat Analysis”有22道考題考試時間為150分鐘,通過分數線的百分比為75%左右,即每部分正確率為75%即可通過考試.

    CIW認證的考試途徑和報考條件

    如要申請CIW安全分析師證書,考生必須至少已經獲得下表列出的資格證書中的一種,並將相關證明文件寄往CIW中心,同時訪問認證機構的網站查詢獲得的證書是否通用。報考CIW安全分析師的先決條件/證書名稱/版本號。
      
    Microsoft Certified Systems Engineer(MCSE) NT4.0/2000/2003
      Certified Novell engineer(CNE) NetWare 4/5
      Cisco Certified Network Associate(CCNA)
      Cisco Certified Network Professional(CCNP)
      Cisco Certified Internetwork Expert(CCIE)
      Linux Professional Institute(LPI) Level 2
      SAIR Linux Certified Engineer Level 2

  • 为什么收不到邮件?

    =CE=AA=CA=B2=C3=B4=CA=D5=B2=BB=B5=BD=D3=CA=BC=FE=A3=BF=

  • [ithome]中文電腦書排行榜

    No1. ASP.NET AJAX 經典範例100─使用VC#、No2. ASP.NET AJAX應用剖析立即上手、No3. 軟體測試實務講座─來自矽谷的技術經驗與心得分享…
     
    1. ASP.NET AJAX 經典範例100─使用VC#章立民研究室/著
    碁峰出版
    售價:750元

    2. ASP.NET AJAX應用剖析立即上手
    董大偉/著
    博碩出版
    售價:580元

    3. 軟體測試實務講座─來自矽谷的技術經驗與心得分享
    李幸超/著
    博碩出版
    售價:290元

    4. JavaScript 大全( JavaScript: The Definitive Guide, 5/e)
    David Flanagan/著;
    陳建勳/譯
    歐萊禮出版
    售價:1200元

    5. SQL 語法範例辭典
    陳亦苓/著
    旗標出版
    售價:550元

    6. 深入淺出物件導向分析與設計(Head First Object-Oriented Analysis and Design)
    Brett McLaughlin、Gary Pollice、David West /著;
    楊仁和/譯
    歐萊禮出版
    售價:880元

    7. Microsoft Office SharePoint Server 2007新一代企業Web解決方案(第一集)
    恆逸資訊屠立剛、吳翠鳳/著
    悅知出版
    售價:690元

    8. 嵌入式設計及Linux 驅動開發指南─基於 ARM 9 處理器, 2/e
    孫天澤、袁文菊/著
    大學出版
    售價:420元

    9. ASP.NET 2.0 深度剖析範例集
    董大偉/著
    博碩出版
    售價:650元

    10. Java 認證SCJP 5.0猛虎出閘
    段維瀚/著
    碁峰出版
    售價:650元

    資料來源:天瓏資訊圖書,2007.07.16

  • Microsoft SQL Server 2008: Grow Your Database Potential

    Microsoft Learning introduces a new suite of certifications for Microsoft® SQL Server® 2008, offering you more choices and simpler paths to follow to achieve your certification goals.You can demonstrate your depth of knowledge in one specific area, earn multiple MCTS certifications to show breadth across different areas, or build on the MCTS to earn a Professional Series credential.
    MCTS certifications for SQL Server 2008
    When you earn a Microsoft Certified Technology Specialist (MCTS) certification, you validate your deep technical knowledge and skill using the features and functionality of key technology areas in Microsoft SQL Server 2008.
    Three MCTS certifications on Microsoft SQL Server 2008 are available: MCTS: SQL Server 2008, Implementationand Maintenance; MCTS: SQL Server 2008,Database Development; and MCTS: SQL Server 2008,Business Intelligence Development and Maintenance.

    MCITP certifications for SQL Server 2008

    With a Microsoft Certified IT Professional (MCITP),credential you can distinguish yourself as an IT professional with the current skills and proven capabilities to work effectively with Microsoft SQL Server 2008.

    At the MCITP level there are also three Microsoft SQL Server 2008 certification: MCITP: Database Administrator 2008; MCITP: Database Developer 2008;and MCITP: Business Intelligence Developer 2008.You can read more about the new SQL Server certifications at http://www.microsoft.com/learning/mcp/sql/2008/default.mspx

    Download: Microsoft SQL Server 2008 certification

  • 利用Oracle 10g 的MODEL SQL 進行行間計算

    以產品產量表為例,一個工廠(用code 表示)生產多種產品(用p_id 表示),每種產品具有生產量(v1)和銷售量(v2)產品代碼具有審核關係,如’10’=’30’+’31’,其中’10’代表大類,’30’和’31’代表’10’大類下的小類。
    SQL>createtablet603(codevarchar(10),p_idvarchar(7),v1number(10),v2number(1
    0));
    Tablecreated.
    SQL>insertintot603values(‘600001′,’30’,1,1);
    SQL>insertintot603values(‘600001′,’31’,1,1);
    SQL>insertintot603values(‘600001′,’10’,2,2);
    SQL>insertintot603values(‘600002′,’10’,3,2);
    SQL>insertintot603values(‘600002′,’31’,2,1);
    SQL>insertintot603values(‘600002′,’30’,2,1);
    SQL>commit;
    Commitcomplete.
    SQL>select*fromt603;
    CODEP_IDV1V2
    ————————————-
    6000013011
    6000013111

    6000011022
    6000021032
    6000023121
    6000023021
    6rowsselected.
    SELECTcode,
    p_id,v1
    FROMt603
    WHEREcodeIN(‘600001′,’600002’)
    MODELRETURNUPDATEDROWS
    PARTITIONBY(code)
    DIMENSIONBY(p_id)
    MEASURES(v1)
    RULES(
    v1[‘err1′]=v1[’30’]+v1[’31’]-v1[’10’])
    ORDERBYcode,p_id;
    其中rule 表示計算規則,’err1’表示這條審核關係的代號,它的值等於P_ID 為’30’的v1 值+P_ID 為’31’的v1 值-P_ID 為’10’的v1 值PARTITION BY (code)表示按工廠分區,即審核在一個工廠內的產品MODEL 關鍵字後面的RETURN UPDATED ROWS 子句將結果限制為在該查詢中創建或更新的那些行。使用該子句是使結果集只包含新計算的值,在本例中就是審核結果

    CODEP_IDV1
    —————————
    600001err10
    600002err11
    如果返回值=0,表示v1[’30’] + v1[’31’] =v1[’10’]審核通過,否則,審核不通過

    (更多…)

  • Oracle 10g數據庫中如何分析響應時間

    在Oracle10g 中,以前版本中比較難於獲取的響應時間數據將會變得非常容易獲取。在以前看來,為了盡量獲得數據庫的最佳性能,Oracle 的DBA 們和性能分析專家一直很困難獲得系統以及用戶會話活動的一致的響應時間數據。 DBA 們面臨的問題一直以來包括兩個方面:第一個方面是準確定位數據庫或者用戶會話究竟在哪裡消耗了時間;第二個方面就是確定用戶體驗的客觀性質在數據庫中產生所有可能的行為和交互作用,這些任務都不是沒有價值的。  

    Oracle 等待接口,在之前的很早的Oracle 數據庫版本中開始介紹的,對於那些知道如何使用等待接口的管理員來說這已經成為一個偉大的開始,即使它仍然缺乏告訴DBA 系統或者用戶會話是否有效的處理了事務或者查詢這個理想的能力。啟用和鑽研跟踪文件能夠存儲這個級別上的詳細信息,但是對於大多數超負荷工作管理大型數據庫的DBA 們,這個鑽研是奢侈的而耗費時間的。幸運的是,那些將數據庫升級到Oracle10g 的DBA 們將會發現找到主要的響應時間變得很容易,可以允許一個非常好的圖表來顯示系統和會話級的響應時間數據。很重要的一點,Oracle 的ADDM 提供了一個查看響應時間的方法,通過自動分析收集的統計信息,識別問題區域,甚至可以通過Oracle 企業管理器網絡控制的圖形界面提供建議。此外,與我們這裡討論相關的是Oracle10g 數據庫的歷史數據機制允許DBA 們按時查看對響應時間趨勢的分析,這將有助於DBA 們確定事務/系統的高峰時期,更好的定位那些拉長批處理週期和ETL 作業的進程和SQL 語句。

    (更多…)

  • LPI啟動新的和修訂LPI-1和LPI-2 LINUX認證程序

    全球首屈一指的Linux認證機構宣布,它已經完成了廣泛的審查和更新考試目標LPIC – 1LPIC – 2認證計劃。新版本的這些考試將予以公佈,並可以在2009年4月1日開始生效。

    全文如下:
     
    LPI set to launch new and revised LPIC-1 and LPIC-2 Linux certification programs
     
    (Sacramento, USA: November 12, 2008) The Linux Professional Institute (LPI), the world’s premier Linux certification organization, announced it has completed an extensive review and update of the exam objectives for the popular LPIC-1 and LPIC-2 certification programs . New versions of these exams will be published and available on April 1, 2009.
    “This update of our LPIC-1 and LPIC-2 certification program is a significant milestone in LPI’s history and exemplifies our extensive, ongoing and transparent communications with industry leaders and the Open Source community on what are the necessary skill sets for a Linux professional, ” said Jim Lacey, President and CEO of the Linux Professional Institute. Mr. Lacey noted many of the changes to the exams are the result of extended consultations with partner organizations in the field and others that support LPI’s certification program: “As an example, we have broadened the scope of the LPIC-1 exams to appeal to a wider range of Linux professionals while focusing in-depth system administration and networking skills in the LPIC-2 certification.” Mr. Lacey also indicated that the increasing global relevance of the LPIC program has made it necessary that these new exams are much more sensitive to non-English exam candidates and include a greater amount of questions around localization, internationalization and accessibility issues.
    Revised exam objectives for LPIC-1 and LPIC-2 are available on LPI’s public wiki: https://group.lpi.org/publicwiki/bin/view/Examdev/WebHome. Candidates should note however that prior to April 1, 2009 exams will continue to be based on the “old” objectives for LPIC-1 and LPIC-2: http://www.lpi.org/eng/certification/the_lpic_program/lpic_1 and http://www.lpi.org/eng/ certification/the_lpic_program/lpic_2.
    The Linux Professional Institute is globally supported by the IT industry, enterprise customers, community professionals, government entities and the educational community. LPI’s certification program is supported by an affiliate network spanning five continents and is distributed worldwide in multiple languages in more than 7,000 testing locations . Since 1999, LPI has delivered more than 195,000 exams and 62,000 LPIC certifications around the world.
     
    About the Linux Professional Institute:
     
    The Linux Professional Institute promotes and certifies essential skills on Linux and Open Source technologies through the global delivery of comprehensive, top-quality, vendor-independent exams. Established as an international non-profit organization in 1999 by the Linux community, the Linux Professional Institute continues to demonstrate recognized global leadership in the certification of Linux professionals. LPI advances the Linux and Open Source movement through strategic partners, sponsorships, innovative programs and community development activities. LPI’s major financial sponsors are Platinum Sponsors IBM, Linux Journal, Linux Magazine, Novell , SGI, and TurboLinux as well