Java關(guān)鍵字: transient | strictfp | volatile

          Posted on 2006-03-02 20:53 killvin 閱讀(512) 評論(0)  編輯  收藏 所屬分類: java

          Java Language Keywords

          Here's a list of keywords in the Java language. These words are reserved — you cannot use any of these words as names in your programs. true, false, and null are not keywords but they are reserved words, so you cannot use them as names in your programs either.

          abstract    |   continue    |   for    |    new     |   switch
          assert***  |   default     |   goto*     |   package     |   synchronized
          boolean    |   do     |   if     |   private     |   this
          break         |   double     |   implements    |   protected    |   throw
          byte            |   else     |   import     |   public  throws
          case          |   enum****    |   instanceof    |   return     |   transient 
          catch         |   extends     |   int     |   short     |   try
          char           |   final     |   interface    |   static     |   void
          class         |   finally     |   long     |   strictfp**    |   volatile
          const*       |   float     |   native     |   super     |   while


          *   not used
          **   added in 1.2
          ***   added in 1.4 
          ****   added in 5.0                                    

           

          Key: strictfp**

          使用對象:類、方法

          自Java2以來,Java語言增加了一個關(guān)鍵字strictfp,雖然這個關(guān)鍵字在大多數(shù)場合比較少用,但是還是有必要了解一下。

          strictfp的意思是FP-strict,也就是說精確浮點的意思。在Java虛擬機進行浮點運算時,如果沒有指定strictfp關(guān)鍵字時,Java的編譯器以及運行環(huán)境在對浮點運算的表達(dá)式是采取一種近似于我行我素的行為來完成這些操作,以致于得到的結(jié)果往往無法令你滿意。而一旦使用了strictfp來聲明一個類、接口或者方法時,那么所聲明的范圍內(nèi)Java的編譯器以及運行環(huán)境會完全依照浮點規(guī)范IEEE-754來執(zhí)行。因此如果你想讓你的浮點運算更加精確,而且不會因為不同的硬件平臺所執(zhí)行的結(jié)果不一致的話,那就請用關(guān)鍵字strictfp。

          你可以將一個類、接口以及方法聲明為strictfp,但是不允許對接口中的方法以及構(gòu)造函數(shù)聲明strictfp關(guān)鍵字,例如下面的代碼:

          1. 合法的使用關(guān)鍵字strictfp

          strictfp interface A {}

          public strictfp class FpDemo1 {
              strictfp void f() {}
          }

          2. 錯誤的使用方法

          interface A {
              strictfp void f();
          }

          public class FpDemo2 {
              strictfp FpDemo2() {}
          }

          一旦使用了關(guān)鍵字strictfp來聲明某個類、接口或者方法時,那么在這個關(guān)鍵字所聲明的范圍內(nèi)所有浮點運算都是精確的,符合IEEE-754規(guī)范的。例如一個類被聲明為strictfp,那么該類中所有的方法都是strictfp的。

           

          Keys: volatile

          使用對象:字段

          介紹:因為異步線程可以訪問字段,所以有些優(yōu)化操作是一定不能作用在字段上的。volatile有時

          可以代替synchronized。

           

          Keys:transient

            使用對象:字段

            介紹:字段不是對象持久狀態(tài)的一部分,不應(yīng)該把字段和對象一起串起。

          主站蜘蛛池模板: 沙坪坝区| 凤阳县| 阳高县| 黔南| 启东市| 高邮市| 龙川县| 伊金霍洛旗| 郎溪县| 弋阳县| 五华县| 海原县| 新田县| 那曲县| 周口市| 东光县| 若羌县| 安仁县| 和平县| 教育| 措美县| 芜湖县| 吉木萨尔县| 图木舒克市| 山西省| 台江县| 张北县| 正宁县| 高邮市| 大竹县| 滦平县| 建湖县| 潍坊市| 安顺市| 科技| 宣武区| 牟定县| 若尔盖县| 林甸县| 海阳市| 霍州市|