Posted on 2006-03-02 20:53
killvin 閱讀(511)
評論(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語言增加了一個關鍵字strictfp,雖然這個關鍵字在大多數場合比較少用,但是還是有必要了解一下。
strictfp的意思是FP-strict,也就是說精確浮點的意思。在Java虛擬機進行浮點運算時,如果沒有指定strictfp關鍵字時,Java的編譯器以及運行環境在對浮點運算的表達式是采取一種近似于我行我素的行為來完成這些操作,以致于得到的結果往往無法令你滿意。而一旦使用了strictfp來聲明一個類、接口或者方法時,那么所聲明的范圍內Java的編譯器以及運行環境會完全依照浮點規范IEEE-754來執行。因此如果你想讓你的浮點運算更加精確,而且不會因為不同的硬件平臺所執行的結果不一致的話,那就請用關鍵字strictfp。
你可以將一個類、接口以及方法聲明為strictfp,但是不允許對接口中的方法以及構造函數聲明strictfp關鍵字,例如下面的代碼:
1. 合法的使用關鍵字strictfp
strictfp interface A {}
public strictfp class FpDemo1 {
strictfp void f() {}
}
2. 錯誤的使用方法
interface A {
strictfp void f();
}
public class FpDemo2 {
strictfp FpDemo2() {}
}
一旦使用了關鍵字strictfp來聲明某個類、接口或者方法時,那么在這個關鍵字所聲明的范圍內所有浮點運算都是精確的,符合IEEE-754規范的。例如一個類被聲明為strictfp,那么該類中所有的方法都是strictfp的。
Keys: volatile
使用對象:字段
介紹:因為異步線程可以訪問字段,所以有些優化操作是一定不能作用在字段上的。volatile有時
可以代替synchronized。
Keys:transient
使用對象:字段
介紹:字段不是對象持久狀態的一部分,不應該把字段和對象一起串起。