abstract assert boolean break byte
case catch char class const
continue default do double else
enum extends final finally float
for if implements import instanceof
int interface long native new
package private protected public return
short static strictfp super switch
synchronized this throw throws transient
try void volatile while
現版本未使用,為未來擴展預留:
byValue cast false future generic
inner operator outer rest true
var goto const null
注意:const、goto 同時出現在兩個列表中(不同來源分類差異),實際均為保留字,不可作標識符。true、false、null 技術上屬於字面量,但常被歸類為保留字。
Which are keywords/reserved words in Java?
a) if b) then c) goto d) while e) case f) sizeof
答案:a, c, d, e
解析:then、sizeof 為 C/C++ 關鍵字,Java 無此關鍵字。
Which are Java keywords?
a) double b) Switch c) then d) instanceof
答案:a, d
解析:所有關鍵字均為小寫,Switch 大寫無效;instanceof 為關鍵字非方法。
Which are keywords in Java?
a) default b) NULL c) String d) throws e) long f) true
答案:a, d, e, f
解析:NULL 大寫非關鍵字(字面量為 null);String 為類名;true 為 boolean 字面量/保留字。
sizeof、friendly、delete 等非 Java 關鍵字true/false/null 為字面量;String/System 為類名const、goto 編譯報錯| 類別 | 關鍵字 |
|---|---|
| 訪問控制 | private, protected, public |
| 類/接口/枚舉定義 | class, interface, enum, extends, implements |
| 基本類型 | boolean, byte, char, short, int, long, float, double, void |
| 流程控制 | if, else, switch, case, default, for, while, do, break, continue, return |
| 異常處理 | try, catch, finally, throw, throws |
| 修飾符 | abstract, final, static, synchronized, volatile, transient, native, strictfp |
| 包/導入 | package, import |
| 其他 | this, super, new, instanceof, assert, const*, goto* |
* 標記為保留字