从起名说起

      古语云:“赐予千金,不如赐子一艺,教子一艺,不如赐子好名。”名字的重要性不言而喻,名字起好了,以后可以光宗耀祖,取不好虽然不至于遗臭万年,但是如果您还碰巧出名了,那可很容易贻笑大方。拿我们大明朝的开国皇帝来说,朱元璋--元指元朝,璋是一种尖锐的玉器,朱诛同音,所以朱元璋这个名字就是诛灭元朝的利器。这个名字是朱元璋做不成和尚,投奔郭子仪,也就是我们所熟知的大脚皇后--马大脚的义父所取。而朱元璋也从此开始飞黄腾达之路,从一个衣不遮体,食不果腹的小人物,一步步的走到金銮宝座之上。朱元璋原来的名字大家可能并不熟悉,朱元璋原名叫朱重八,也就是朱八八的意思。如果他一直叫这个这个名字可能他就可能成为名字最为奇怪的皇帝了。
      由此可见名字对于一个人是至关重要了。在Java这个语言中是不是也是这样的呢,大家伙可能说了,那没那么重要吧,只要能用不就行了?其实不然,因为Java命名不用中文大家也需不觉得别扭,如果你把你命名的东西翻译成中文可能感觉就很不同了。举大宅门的例子来说,“类”--医生,太医,名词;接口--看病的,制药的,做生意的,形容词;他们有什么能力--方法,看病,治病,挣钱,救人,动名词。我们取东西,得从别的地方“拿,get”过去,我们搁东西,是“放回,set”去。您肯定不乱用词汇,因为乱用让人笑话。换到Java里也一样,虽然是英文,好像好点,但是一旦您乱取得名字让老外一看,不也丢您的人么。所以取名字在Java里也是一样重要的。对了还有一点也比较重要就是不能跟名人尤其是领导人取相同的名字,在封建社会得必会皇帝的名字,java里也一样,也不能用关键字来命名。
     把Java的命名规则列在下面仅供参考:
    Classes and interfaces The first letter should be capitalized, and if several words are linked together to form the name, the first letter of the inner wordsshould be uppercase (a format that's sometimes called "camelCase"). For
classes, the names should typically be nouns. For example:
      Dog
      Account
      PrintWriter

   For interfaces, the names should typically be adjectives like:
      Runnable
      Serializable

    Methods The first letter should be lowercase, and then normal camelCase rules should be used. In addition, the names should typically be verb-noun pairs. For example:
      getBalance
      doCalculation
      setCustomerName

    Variables Like methods, the camelCase format should be used, starting with a lowercase letter. Sun recommends short, meaningful names, which sounds good to us. Some examples:
      buttonWidth
      accountBalance
      myString

    Constants Java constants are created by marking variables static and final. They should be named using uppercase letters with underscore characters as separators:
      MIN_HEIGHT

posted on 2009-07-30 16:27  流涧  阅读(292)  评论(0)    收藏  举报

导航