<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 81  文章 - 1033  trackbacks - 0
    <2007年4月>
    25262728293031
    1234567
    891011121314
    15161718192021
    22232425262728
    293012345

    在浮躁的年代里,我們進(jìn)取心太切,患得患失;虛榮心太強(qiáng),戰(zhàn)戰(zhàn)兢兢。一心爭(zhēng)強(qiáng)好勝,惟恐榜上無名。
    I think I can fly , and flying like a bird !
    程序員一名,已售出,缺貨中!

    我的郵件聯(lián)系方式

    用且僅用于MSN

    博客點(diǎn)擊率
    free web counter
    free web counter

    常用鏈接

    留言簿(36)

    隨筆檔案

    搜索

    •  

    積分與排名

    • 積分 - 187486
    • 排名 - 309

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

          學(xué)Java也有些年頭了,但無時(shí)無刻不深感Java基礎(chǔ)知識(shí)、Java的OO以及Java的API也就是所謂的Core Java之重要性,從來不敢放松對(duì)它們的反復(fù)學(xué)習(xí)和提煉。并且事實(shí)證明在對(duì)它們的慢慢積累和深透的學(xué)習(xí)中悟出更多的編程之道,編程能力也在一步步見長(zhǎng)。即使在轉(zhuǎn)而學(xué)其它語言的時(shí)候應(yīng)用相應(yīng)套路也會(huì)事半功倍(不過抓住不同語言之區(qū)別也至關(guān)重要,要不會(huì)走很多彎路)。

          最近決定重讀Core Java,并希望能找到以前遺漏的部分,并梳理出個(gè)更清晰的頭緒。做到先把書由薄讀厚,然后把書由厚讀薄!(再說計(jì)算機(jī)的書本來就沒有薄的,汗)不打算大篇幅的把內(nèi)容都貼上來,只是想借助blog記錄些需要時(shí)刻注意的重點(diǎn)供自己與大家分享。

          言歸正傳,拋個(gè)磚引個(gè)玉,先來一篇Java基礎(chǔ)類型,可能你覺得這是Java里最簡(jiǎn)單的概念,其實(shí)里面的東西未必每個(gè)人都清楚,并能運(yùn)用的很好。


          Java整型

    int  4字節(jié) -2147483648 ~ 2147483647   (正好超過20億)
    short 2字節(jié) -32768 ~ 32767
    long 8字節(jié) -9223372036854775808 ~ 9223372036854774807
    byte 1字節(jié) -128 ~ 127



          浮點(diǎn)類型

    float 4字節(jié) 大約±3.40282347E+38F (有效位數(shù)為6-7位)
    double 8字節(jié) 大約±1.79769313486231570E+308 (有效位數(shù)為15位)

    一些需要注意:

    1if(x == Double.NaN)  // is never true

    1if(Double.isNaN(x))  // check whether is "not a number"

          浮點(diǎn)數(shù)值不適合用于禁止出現(xiàn)舍入誤差的金融計(jì)算中。例如System.out.println( 2.0 - 1.1);將打印0.899999999999999,而不是0.9。因?yàn)楦↑c(diǎn)數(shù)值采用二進(jìn)制系統(tǒng)表示,而二進(jìn)制無法精確表示分?jǐn)?shù)1/10,就像十進(jìn)制無法精確表示1/3一樣。如果需要在數(shù)值計(jì)算中不含有舍入誤差,就應(yīng)該使用BigDecimal類。


          char類型

          在Java中,char類型用UTF-16編碼描述一個(gè)代碼單元。強(qiáng)烈建議不要在程序中使用char。


          boolean類型

          在C或C++中數(shù)值或指針可以代替boolean的值,0相當(dāng)于flase,非0相當(dāng)于true,而在Java中則不行,并且在編譯時(shí)就會(huì)報(bào)錯(cuò)。
    posted on 2007-04-03 01:48 cresposhi 閱讀(8759) 評(píng)論(35)  編輯  收藏

    FeedBack:
    # re: Core Java之Java基本類型 2007-04-03 01:52 cresposhi
    剛?cè)チ颂薆logJava首頁,文章寥寥,又一次感到BlogJava之凄涼,哎,眼淚嘩嘩的,睡覺去了。。。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-03 02:37 sinoly
    呵呵,小伙子還是精神很好嘛。。。。
      回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-03 08:51 liigo
    “強(qiáng)烈建議不要在程序中使用char”
    很想知道理由,謝謝。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型[未登錄] 2007-04-03 08:54 阿蜜果
    做到先把書由薄讀厚,然后把書有厚讀薄!
    中意這句。。。。。。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-03 09:27 穎穎
    這丑個(gè)頭,難怪人家都不寫了呢,呵呵  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-03 09:38 cresposhi
    @liigo
    這種驚世駭俗的話我肯定是不敢說的,只是從大師的描述中領(lǐng)悟到一點(diǎn)道道。還是把大師的話貼在這里,一切就真相大白了。

    To understand the char type, you have to know about the Unicode encoding scheme. Unicode was invented to overcome the limitations of traditional character encoding schemes. Before Unicode, there were many different standards: ASCII in the United States, ISO 8859-1 for Western European languages, KOI-8 for Russian, GB18030 and BIG-5 for Chinese, and so on. This causes two problems. A particular code value corresponds to different letters in the various encoding schemes. Moreover, the encodings for languages with large character sets have variable length: some common characters are encoded as single bytes, others require two or more bytes.

    Unicode was designed to solve these problems. When the unification effort started in the 1980s, a fixed 2-byte width code was more than sufficient to encode all characters used in all languages in the world, with room to spare for future expansion—or so everyone thought at the time. In 1991, Unicode 1.0 was released, using slightly less than half of the available 65,536 code values. Java was designed from the ground up to use 16-bit Unicode characters, which was a major advance over other programming languages that used 8-bit characters.

    Unfortunately, over time, the inevitable happened. Unicode grew beyond 65,536 characters, primarily due to the addition of a very large set of ideographs used for Chinese, Japanese, and Korean. Now, the 16-bit char type is insufficient to describe all Unicode characters.

    We need a bit of terminology to explain how this problem is resolved in Java, beginning with JDK 5.0. A code point is a code value that is associated with a character in an encoding scheme. In the Unicode standard, code points are written in hexadecimal and prefixed with U+, such as U+0041 for the code point of the letter A. Unicode has code points that are grouped into 17 code planes. The first code plane, called the basic multilingual plane, consists of the "classic" Unicode characters with code points U+0000 to U+FFFF. Sixteen additional planes, with code points U+10000 to U+10FFFF, hold the supplementary characters.

    The UTF-16 encoding is a method of representing all Unicode code points in a variable length code. The characters in the basic multilingual plane are represented as 16-bit values, called code units. The supplementary characters are encoded as consecutive pairs of code units. Each of the values in such an encoding pair falls into an unused 2048-byte range of the basic multilingual plane, called the surrogates area (U+D800 to U+DBFF for the first code unit, U+DC00 to U+DFFF for the second code unit).This is rather clever, because you can immediately tell whether a code unit encodes a single character or whether it is the first or second part of a supplementary character. For example, the mathematical symbol for the set of integers has code point U+1D56B and is encoded by the two code units U+D835 and U+DD6B. (See http://en.wikipedia.org/wiki/UTF-16 for a description of the encoding algorithm.)

    In Java, the char type describes a code unit in the UTF-16 encoding.

    Our strong recommendation is not to use the char type in your programs unless you are actually manipulating UTF-16 code units. You are almost always better off treating strings (which we will discuss starting on page 51) as abstract data types.

      回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-04 11:42 kirari_wxy
    大師也經(jīng)常出錯(cuò)的 呵呵 不過有些還是通用的 帶小數(shù)計(jì)算的問題還是留給BigDecimal吧 這應(yīng)該是很多公司的編碼規(guī)范了  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-04 11:47 kirari_wxy
    不鼓勵(lì)使用char可能是因?yàn)閖ava全部是Unicode編碼 容易造成字符和字符串的問題  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-04 12:32 cresposhi
    @kirari_wxy
    如果需要結(jié)果一致BigInteger和BigDecimal確實(shí)更好。
    至于char的問題其實(shí)是Java里char是用UTF-16的,這樣就有code units 和 code points 這兩個(gè)概念,上面大師已經(jīng)描述過了,char表示一個(gè)code units而對(duì)于常規(guī)字符來講一個(gè)code units就是一個(gè)code points而對(duì)于一些特殊的字符需要兩個(gè)code units來表示,這個(gè)時(shí)候char就會(huì)引起很多混淆,所以最好使用Character或者一些其他的包裝過的類型。
    我覺得國(guó)外的大師一般不隨便亂說話的,而國(guó)內(nèi)的“大師”比較喜歡忽悠大家。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-04 14:02 kirari_wxy
    BigInteger倒是很少用,但是BigDecimal應(yīng)該是編碼規(guī)范了,至少我看到的公司都是這樣,也可能我看到的都是金融業(yè)的公司,對(duì)數(shù)值要求高,而char只要明白原理了應(yīng)該不會(huì)錯(cuò),至少我們系統(tǒng)沒有出現(xiàn)這樣的問題,不過確實(shí)很少用到char。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-04 14:09 cresposhi
    @kirari_wxy
    對(duì),金融的肯定要BigDecimal,要不每次結(jié)果都隨機(jī)那還不汗死~~~
    至于char可能那些特別字符用的比較少吧,等到哪天碰到了找bug要找暈,呵呵。
    JDK5.0里面就提供了很多對(duì)code points的方法支持,比如String里面Character里面都有。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-04 14:29 kirari_wxy
    可惜大型系統(tǒng)都是jdk1.4的,至今沒有用到1.5,j2ee更新慢,中間件server也更新慢,開發(fā)系統(tǒng)的也不敢冒險(xiǎn)。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-04 14:49 cresposhi
    @kirari_wxy
    其實(shí)JEE現(xiàn)在不也有了J5EE,各大Application Server廠商也都在新的產(chǎn)品線全面擁抱了JDK5,大部分活躍的開源產(chǎn)品也擁抱了JDK5,并有很多應(yīng)用面極廣泛的開源產(chǎn)品的新特性都是依賴JDK5的新特性,必須要JDK5的支持,如spring、hibernate等。
    不過確實(shí)非常多比較慎重的團(tuán)隊(duì)依然守護(hù)這JDK1.4.2,不愿意冒險(xiǎn)。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-04 17:40 穎穎
    一哈不來你們都聊起來了啊  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-04 18:59 cresposhi
    @穎穎
    做技術(shù)最開心的莫過于遇到一個(gè)能討論的人,呵呵  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-05 17:32 kirari_wxy
    呵呵,上班沒事隨便聊聊,做大型系統(tǒng)都是很謹(jǐn)慎的,在沒有不能解決的問題發(fā)生的情況下不會(huì)使用新技術(shù),也不會(huì)升級(jí)中間件系統(tǒng)的,甚至是jdk。不升級(jí)版本是因?yàn)槌隽藛栴}誰也負(fù)不了這個(gè)責(zé)任,不使用新技術(shù)是因?yàn)槭褂米詈?jiǎn)單的技術(shù)才會(huì)降低開發(fā)門檻,人力資源才會(huì)充足。而且這些大型系統(tǒng)即使用hibernate,也是假的,最多就是一個(gè)單表查詢。聽說工商銀行的核心系統(tǒng)用了spring,我沒見過,其他的金融公司的核心系統(tǒng),怕是沒人敢用的。我們公司4000萬美元的項(xiàng)目都不敢用。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-05 17:36 cresposhi
    4KW dollar。。。我還沒有機(jī)會(huì)。。。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-05 17:59 kirari_wxy
    我也就04年做過一段時(shí)間,后來就換到其他項(xiàng)目了。這個(gè)項(xiàng)目到現(xiàn)在還沒有完工,無數(shù)人做了3年多了,哎,大項(xiàng)目有時(shí)也蠻痛苦,還好是賺錢的,人力成本也是客戶出錢,每人每月RMB12500,出差每天補(bǔ)助將近RMB200。我沒有趕到好時(shí)候啊,呵呵。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-05 19:21 cresposhi
    呵呵,那什么時(shí)候給我介紹個(gè)工作干干
    在小公司呆煩了。。。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-09 14:01 kirari_wxy
    有機(jī)會(huì)可以來我們公司試試  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-09 14:28 cresposhi
    oh yeah,能不能把網(wǎng)站告訴我觀摩一下  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-10 11:07 穎穎
    是啊,順便把我也招過去列  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-10 11:13 kirari_wxy
    http://www.ebaotech.com/

    這是我目前工作的公司 可以先看看 不過感覺最近沒有前幾年好了  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-10 14:01 穎穎
    呵呵,那就去別的地方,哎,哪個(gè)知道哪個(gè)公司現(xiàn)在好啊  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-10 14:29 kirari_wxy
    有機(jī)會(huì)就跳,沒機(jī)會(huì)就混著,呵呵,我的目標(biāo)是爭(zhēng)取明年去法國(guó)轉(zhuǎn)轉(zhuǎn)。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-10 16:56 穎穎
    你轉(zhuǎn)的還滿遠(yuǎn)列  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-10 18:05 kirari_wxy
    我在武漢搞了3到4年,來上海也差不多3到4年了,應(yīng)該再換一個(gè)地方看看了,呵呵,男的就應(yīng)該到處轉(zhuǎn)轉(zhuǎn)。。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-10 19:36 cresposhi
    呵呵,老人了。多給點(diǎn)意見啊,thanks
    是應(yīng)該到處轉(zhuǎn)轉(zhuǎn),我就是覺得我現(xiàn)在眼界太有限了  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-11 09:25 穎穎
    那我還在武漢待了24年了列,還老些,都冒轉(zhuǎn),  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-11 09:26 cresposhi
    美女怎么能隨便透漏年齡列,呵呵  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-11 09:50 kirari_wxy
    要是這樣說的話,我離開武漢的時(shí)候都已經(jīng)不止24歲了咧,呵呵。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-11 10:56 穎穎
    又不老,怕什么,呵呵那你現(xiàn)在。。。。那不是更老了。。  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2007-04-11 15:35 cresposhi
    人家那叫成熟嘛,呵呵  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2008-11-08 13:36 drz2008mx@163.com
    BigDecimal t1 = new BigDecimal(2.0),t2 = new BigDecimal(-1.1);
    System.out.println(t1.add(t2).toString());

    效果: 0.899999999999999911182158029987476766109466552734375

    解決不了 舍入誤差問題。在些情況下還是會(huì)出錯(cuò)!  回復(fù)  更多評(píng)論
      
    # re: Core Java之Java基本類型 2008-11-20 13:39 luguo
    @drz2008mx@163.com
    你的構(gòu)造函數(shù)用錯(cuò)了,用了BigDecimal(double),double本來就不是準(zhǔn)確地。得到的BigDecimal也就不對(duì)了,做出來的結(jié)果就不對(duì)了。

    BigDecimal t1 = new BigDecimal("2.0"),t2 = new BigDecimal("-1.1");
    System.out.println(t1.add(t2).toString());  回復(fù)  更多評(píng)論
      

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲综合伊人制服丝袜美腿| 亚洲gv猛男gv无码男同短文| 97在线观免费视频观看| 成人免费无码大片A毛片抽搐色欲| 啦啦啦在线免费视频| av无码东京热亚洲男人的天堂| 亚洲偷自拍拍综合网| 精品亚洲国产成AV人片传媒| 亚洲一级特黄特黄的大片| 黄在线观看www免费看| 国产成人免费a在线资源| 精品国产综合成人亚洲区| 国产亚洲AV夜间福利香蕉149| 亚洲国产精品婷婷久久| 在线观看亚洲专区| 最近国语视频在线观看免费播放| 97av免费视频| 丁香亚洲综合五月天婷婷| igao激情在线视频免费| 日本妇人成熟免费中文字幕| 亚洲日韩精品一区二区三区| 亚洲日本va一区二区三区| 97在线免费视频| 亚洲精品国产免费| jizz免费观看| 亚洲高清在线视频| av片在线观看永久免费| 亚洲国产精品无码专区影院 | 亚洲精品久久久www| 亚洲乱码卡三乱码新区| 青柠影视在线观看免费高清| 日本媚薬痉挛在线观看免费| 亚洲av永久无码精品天堂久久| 一区二区三区在线免费看| 在线日韩日本国产亚洲| 99久久免费精品高清特色大片| 亚洲av午夜成人片精品网站 | 久久国产乱子免费精品| 亚洲一区二区三区香蕉| 亚洲一区二区三区免费视频| 亚洲最大成人网色|