亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? good java style part 2.txt

?? java學(xué)習(xí)文檔
?? TXT
字號:
作者:jeru
email: jeru@163.net
日期:8/9/2001 6:12:34 PM
Good Java Style: Part 2
By Thornton Rose 

Introduction
This is the conclusion of a two-part series on Java coding style. In Good Java Style: Part 1 

, I introduced my case for writing Java code using good habits, explained why we should care about the way our code looks, and illustrated some general elements of good Java style. In this part, I illustrate more elements of good style and bring my case to a conclusion. 

Source Files
There are many ways that a Java source file can be organized. Here is one that works well: 


File header comment (optional). 
Package declaration. 
Blank line or other separator. 
Import statements. 
Blank line or other separator. 
Class(es). 

Example 1. Bad File Organization. 


   package org.rotpad;
   import java.awt.*;
   import javax.swing.event.*;
   import org.javacogs.*;
   import javax.swing.*;
   import java.awt.event.*;
   class Foo {
    ...
   }
   public class RotPad extends JFrame {
    ...
   }


Example 2. Good File Organization. 


   package org.rotpad;
   
   // Java classes
   import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;
   import javax.swing.event.*;
   
   // JavaCogs classes
   import org.javacogs.*;
   
   /**
    * RotPad is a simple GUI application for performing rotation ciphers on plain 
    * text.
    *
    * @author Thornton Rose
    * @version 1.0
    */
   public class RotPad extends JFrame {
      ...
   }
   
   //-----------------------------------------------------------------------------
   
   /**
    * Foo is ...
    *
    * @author Thornton Rose
    * @version 1.0
    */
   class Foo {
      ...
   }


Import Statements
A complex class can have a large number of imports, which can get unruly, especially if you prefer to import individual classes instead of whole packages (e.g., java.awt.*). To get a handle on imports, organize them as follows: 


Java standard classes (java.*). 
Java extension classes (javax.*). 
Third-party classes. 
Application classes. 

Be sure to comment the third-party and application classes, particularly those that do not have obvious names. Use end-of-line comments, or put a comment at the beginning of the section. Also, if you really want to be a perfectionist, order each group of imports alphabetically. 

Example 3. Bad Import Style.


   import java.util.*;
   import javax.swing.*;
   import java.awt.event*;
   import com.gensym.com.*;
   import javax.swing.table.*;
   import com.pv.jfcx.*;
   import java.awt.*;
   import com.melthorn.util.*;


Example 4a. Good Import Style. 


   import java.awt.*;
   import java.awt.event*;
   import java.util.*;
   import javax.swing.table.*;
   import com.gensym.com.*;     // BeanXporter
   import com.pv.jfcx.*;        // ProtoView
   import com.melthorn.util.*;  // Utilities

Example 4b. Good Import Style. 


   
   // Java classes
   import java.awt.*;
   import java.awt.event*;
   import java.util.*;
   import javax.swing.table.*;
                           
   // BeanXporter
   import com.gensym.com.*;     
                           
   // ProtoView GUI components
   import com.pv.jfcx.*;
                           
   // Application classes
   import com.melthorn.util.*;


Classes
Organizing a Java source file without organizing the classes in it would not gain you much in the way of proper style. Here's how to organize the classes in your source files: 


Javadoc comment or other header comment. 
Class declaration. 
Field declarations. 
Blank line or other separator. 
Constructors. 
Blank line or other separator. 
Methods, except main()
 
, grouped logically. 
Blank line or other separator. 
Inner classes. 
Blank line or other separator. 
main()
 
. 

Example 5. Bad Class Style. 


   // RotPad -- GUI app. for ROT ciphering
   public class RotPad extends JFrame {
   private static final String TRANSFORM_ROT13    = "ROT13";
   private static final String TRANSFORM_ROT13N5  = "ROT13N5";
   private static final String TRANSFORM_ROTASCII = "ROT-ASCII";
   
   private void jbInit() throws Exception {
      ...
   }
   
   public static final String TITLE   = "RotPad";
   public static final String VERSION = "1.0";
   
   public static void main(String[] args) {
      ...
   }
   
   public RotPad() {
      ...
   }
   
   private JPanel jPanel1 = new JPanel();
   private JPanel jPanel2 = new JPanel();
   private BorderLayout borderLayout1 = new BorderLayout();
   ...
   }


Example 6. Good Class Style. 


   /**
    * RotPad is a simple GUI application for performing rotation ciphers on plain 
    * text.
    *
    * @author Thornton Rose
    * @version 1.0
    */
   public class RotPad extends JFrame {
      // Public constants
       
      public static final String TITLE   = "RotPad";
      public static final String VERSION = "1.0";
       
      // Private constants
      
      private static final String TRANSFORM_ROT13    = "ROT13";
      private static final String TRANSFORM_ROT13N5  = "ROT13N5";
      private static final String TRANSFORM_ROTASCII = "ROT-ASCII";
     
      // GUI components [JBuilder generated]
       
      private BorderLayout borderLayout1 = new BorderLayout();
      private JPanel jPanel1 = new JPanel();
      private JPanel jPanel2 = new JPanel();
      ...
      
      /**
       * Construct a new instance of this class.
       */
      public RotPad() {
         ...
      }
      
      /**
       * Initialize UI components. [JBuilder generated]
       */
      private void jbInit() throws Exception {
         ...
      }
       
      ...
      
      //--------------------------------------------------------------------------
     
      /**
       * Start the application.
       */
      public static void main(String[] args) {
         ...
      }
   }


Field Declarations
Some classes have a large number of fields, which can become difficult to maintain if they are not organized well. Organize them as follows: 


Public contstants (final and static final). 
Public variables. 
Protected constants. 
Protected variables. 
Package constants. 
Package variables. 
Private constants. 
Private variables. 

Additionally, use the following guidelines for writing field declarations: 


Use one declaration per line. 
Use Javadoc comments on public and protected fields, at minimum. 
Use UPPERCASE for the names of constants. Using uppercase makes them much more obvious in both declarations and expressions. 
If you use a tool that generates field declarations, such as JBuilder or Visual Cafe, keep the generated fields separate from the other fields. It makes maintenance of the UI code much easier. 

Example 7. Bad Field Style. 


   public class CustomerSearchDialog extends JDialog {
      private JLabel firstNameLabel = new JLabel();
      private JLabel lastNameLabel = new JLabel();
      public static final RESULT_SELECT = 1;
      private Vector results = new Vector(); // Search results.
      private DefaultTableModel tableModel = new DefaultTableModel();
      public static final RESULT_CANCEL = 0;
      // ...
   }


Example 8. Good Field Style. 


   /**
    * ...
    */
   public class CustomerSearchDialog extends JDialog {
      /**
       * Indicates that search was cancelled; returned by showDialog() when
       * user clicks cancel button.
       */
      public static final RESULT_CANCEL = 0;
      
      /**
       * Indicates that a customer was selected; returned by showDialog() when
       * user clicks select button.
       */
      public static final RESULT_SELECT = 1;
      
      private Vector            results    = new Vector();             // Search results.
      private DefaultTableModel tableModel = new DefaultTableModel();  // Grid model.
      
      // GUI fields. [JBuilder]
      
      private JLabel firstNameLabel = new JLabel();
      private JLabel lastNameLabel = new JLabel();
      // ...
   }


Method Declarations
Use the following guidelines for writing method declarations: 


Always have a Javadoc comment or some other header comment. 
Always put the access modifier first. 
If the line is too long, break it into one or more lines. 
If the method has more than a few parameters, consider putting each on a separate line. 
Don't put whitespace between the method name and the opening parenthesis ("("). 
Always put whitespace (which could be a line break) between the closing parenthesis (")") and the opening brace ("{"). 

Example 9. Bad Method Style. 


   public int getTypeCount (String custType)
   {
   ...
   }
   static public getInstance(){ ... };
   public void showRange()
      throws RangeException {
    ...
   }


Example 10. Good Method Styles. 


   /**
    * Return the single instance of this class.
    */
   public static CalculationEngine getInstance() {
      return instance;
   }
   
   /**
    * Calculate the consumption coefficient.
    */
   public float calculateConsumptionCoefficient(int base, float variance, 
         int iterations) throws RangeException {
      // ...
   }
  
   /**
    * Calculate the consumption coefficient.
    */
   public float calculateConsumptionCoefficient(
         int base, 
         float variance, 
         int iterations) 
      throws RangeException
   {
      // ...
   }
   
   /**
    * Calculate the consumption coefficient.
    */
   public float calculateConsumptionCoefficient(int base, 
                                                float variance, 
                                                int iterations) 
      throws RangeException
   {
      // ...
   }


Conclusion
In conclusion, I have one final thought for you on the subject of code style. No matter what guidelines you follow, and no matter how fervent your beliefs about things like indent style (cf., Raymond, "Indent Style"), remember that when you write code your overall goal should be to make the code understandable and maintainable by someone else. 

Related Links

Indent Style, The Jargon File, Eric S. Raymond. 
Tabs vs. Spaces, Jamie Zawinski. 
Writing Robust Java Code — The Ambysoft Inc. Coding Standards for Java, Scott Ambler. 
Draft Java Coding Standard, Doug Lea. 
Java Code Conventions, Sun Microsystems, Inc. 
How to Write Doc Comments for Javadoc, Sun Microsystems, Inc. 
The Jargon File (known in print as The New Hacker's Dictionary), Eric S. Raymond. 

About the Author
Thornton Rose is a contract software developer in Atlanta, Ga. He can be reached via e-mail at thornton.rose@mindspring.com. 


?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产成人亚洲精品青草天美| 国内成人精品2018免费看| 亚洲欧美日韩精品久久久久| 一二三区精品视频| 人人狠狠综合久久亚洲| 国产精品一区在线| 欧美日韩成人一区| 久久女同互慰一区二区三区| 亚洲三级免费观看| 国产一区二三区| 91精品欧美综合在线观看最新| 国产精品对白交换视频| 麻豆91在线播放免费| 在线视频一区二区免费| 久久精品亚洲国产奇米99| 亚洲国产日韩在线一区模特| 粉嫩久久99精品久久久久久夜| 欧美色网站导航| 成人免费在线视频观看| 成人丝袜18视频在线观看| 久久综合五月天婷婷伊人| 五月天视频一区| 欧美在线视频日韩| 久久99国产精品麻豆| 日韩欧美国产高清| 一二三四社区欧美黄| 日韩精品一区二区三区四区视频 | 一二三区精品视频| 日韩美一区二区三区| 91麻豆精品在线观看| 国产亚洲精品7777| 欧美系列在线观看| 国产成人亚洲精品青草天美| 三级久久三级久久久| 91精品久久久久久久久99蜜臂| 国模套图日韩精品一区二区| 亚洲一区在线观看免费| 欧美电影一区二区| 美女爽到高潮91| 亚洲欧美区自拍先锋| 久久一区二区三区四区| 69堂精品视频| 91在线无精精品入口| 亚洲综合在线第一页| 欧美国产丝袜视频| 99久久久久久| 国产做a爰片久久毛片| 午夜欧美电影在线观看| 综合分类小说区另类春色亚洲小说欧美| 91精品综合久久久久久| 欧美午夜精品一区| www.亚洲激情.com| 午夜不卡av在线| 综合婷婷亚洲小说| 国产女主播视频一区二区| 色婷婷亚洲精品| 视频一区二区欧美| 亚洲免费高清视频在线| 中文字幕高清不卡| 久久久久久久久久电影| 精品剧情在线观看| 91玉足脚交白嫩脚丫在线播放| 国产精品综合av一区二区国产馆| 日本在线播放一区二区三区| 国产亚洲精品bt天堂精选| 日韩视频中午一区| 99久久国产综合色|国产精品| 国产美女视频91| 国产揄拍国内精品对白| 蜜臀av性久久久久蜜臀aⅴ流畅| 午夜视频在线观看一区| 亚洲一区二区三区四区中文字幕| 樱桃视频在线观看一区| 欧美精品一区二区三区在线| 色婷婷综合久色| 91久久精品国产91性色tv | 亚洲国产成人私人影院tom| 精品国产伦一区二区三区观看体验 | 国产精品午夜电影| 欧美绝品在线观看成人午夜影视| 欧美性猛交xxxx乱大交退制版 | 678五月天丁香亚洲综合网| 欧美猛男超大videosgay| 欧美三级蜜桃2在线观看| 国产a精品视频| 国产精品99久久久久| 亚洲国产精品自拍| 精品一区二区三区免费毛片爱| 亚洲成人精品影院| 欧美精品v日韩精品v韩国精品v| 欧美亚洲一区三区| 欧美系列一区二区| 欧美日韩精品免费| 欧美日韩久久不卡| 欧美一区二区黄色| 91高清在线观看| 欧美视频一区二区三区在线观看| 欧美肥妇free| 久久噜噜亚洲综合| 最新国产の精品合集bt伙计| 亚洲精选免费视频| 奇米影视7777精品一区二区| 国产成都精品91一区二区三| 99久久国产综合精品麻豆| 欧美高清你懂得| wwwwxxxxx欧美| 亚洲日本中文字幕区| 日韩黄色在线观看| 粉嫩欧美一区二区三区高清影视| 色综合色综合色综合| 91精品国产高清一区二区三区| 久久久久久综合| 亚洲第一狼人社区| 国产99久久久国产精品潘金网站| 欧美吞精做爰啪啪高潮| 久久中文字幕电影| 亚洲一卡二卡三卡四卡无卡久久| 久久er99热精品一区二区| 蜜臀av一级做a爰片久久| 国产成人在线网站| 欧美精选一区二区| 亚洲欧洲精品一区二区三区 | 91麻豆精品国产无毒不卡在线观看| 久久新电视剧免费观看| 亚洲高清在线精品| 成人激情开心网| av高清久久久| 日韩精品一区二区三区蜜臀| 亚洲视频一区在线| 国产麻豆日韩欧美久久| 欧美欧美欧美欧美首页| 中文字幕亚洲精品在线观看| 精品亚洲成a人| 欧美三区在线观看| 日韩美女视频一区| 国产精华液一区二区三区| 日韩一二在线观看| 亚洲福利一区二区三区| 91欧美一区二区| 欧美高清在线一区| 国产一区啦啦啦在线观看| 7777精品伊人久久久大香线蕉超级流畅| 亚洲欧洲www| 国产一二精品视频| 精品久久久久久亚洲综合网| 丝袜美腿高跟呻吟高潮一区| 欧美主播一区二区三区美女| 中文字幕一区二区三中文字幕| 国产一区二区三区四区五区美女| 91精品福利在线一区二区三区| 亚洲一区二区三区三| 色激情天天射综合网| 亚洲视频狠狠干| 色综合久久精品| 亚洲精品v日韩精品| 91丝袜美腿高跟国产极品老师| 中文av字幕一区| 成人黄色免费短视频| 国产精品欧美极品| 99久久精品99国产精品| 一色桃子久久精品亚洲| av一区二区不卡| 国产精品不卡在线| 99这里都是精品| 亚洲欧美日韩在线不卡| 色乱码一区二区三区88| 一区二区在线观看av| 在线观看亚洲精品视频| 亚洲一级电影视频| 欧美日韩不卡一区| 日韩二区三区四区| 精品日本一线二线三线不卡| 国产真实乱偷精品视频免| 国产亚洲欧美日韩俺去了| 成av人片一区二区| 日韩理论在线观看| 欧美日韩一区二区三区不卡| 香蕉成人啪国产精品视频综合网| 欧美高清视频不卡网| 精品一区二区三区免费播放| 国产亚洲精品bt天堂精选| av网站免费线看精品| 亚洲自拍偷拍欧美| 日韩午夜激情电影| 高清免费成人av| 亚洲精品国产高清久久伦理二区| 欧美丝袜丝交足nylons图片| 日本 国产 欧美色综合| 久久一夜天堂av一区二区三区| 成人av在线看| 亚洲高清一区二区三区| 欧美精品一区二区在线播放| 9l国产精品久久久久麻豆| 亚洲自拍偷拍综合| 精品国产一区二区三区四区四 | 久久国产三级精品| 国产精品美女一区二区三区| 欧美影院一区二区| 国产综合一区二区| 亚洲一区在线观看视频|