Java予約語一覧(初心者向け・カテゴリ別)
1️⃣ 条件分岐
| 予約語 | 用途 | 例 |
|---|---|---|
if | 条件分岐 | if(x>0){} |
else | 条件分岐 | else{} |
switch | 複数条件分岐 | switch(n){case 1: break;} |
case | switchの条件 | case 1: |
default | switchのデフォルト | default: break; |
2️⃣ ループ
| 予約語 | 用途 | 例 |
|---|---|---|
for | forループ | for(int i=0;i<10;i++) {} |
while | whileループ | while(x>0){} |
do | do-whileループ | do{}while(x>0); |
break | ループ中断 | break; |
continue | 次のループへ | continue; |
3️⃣ クラス・オブジェクト関連
| 予約語 | 用途 | 例 |
|---|---|---|
class | クラス宣言 | class MyClass{} |
interface | インターフェース宣言 | interface Animal{} |
extends | 継承 | class Dog extends Animal{} |
implements | インターフェース実装 | class Dog implements Animal{} |
this | 自分のオブジェクト | this.age = age; |
super | 親クラス参照 | super.method(); |
4️⃣ 型・変数関連
| 予約語 | 用途 | 例 |
|---|---|---|
int, long, short, byte | 整数型 | int x=5; |
float, double | 小数型 | double d=3.14; |
char | 文字型 | char c='A'; |
boolean | true/false | boolean flag=true; |
void | 戻り値なし | void method(){} |
final | 変更不可 | final int MAX=100; |
static | クラス共通 | static int count; |
transient | シリアライズ対象外 | transient int temp; |
volatile | マルチスレッド可視性 | volatile int flag; |
5️⃣ 例外処理
| 予約語 | 用途 | 例 |
|---|---|---|
try | 例外処理開始 | try{} |
catch | 例外処理 | catch(Exception e){} |
finally | 必ず実行 | finally{} |
throw | 例外を投げる | throw new Exception(); |
throws | メソッド宣言で例外 | void m() throws Exception{} |
6️⃣ アクセス制御
| 予約語 | 用途 | 例 |
|---|---|---|
public | どこからでもアクセス | public int age; |
private | クラス内のみ | private int age; |
protected | 同パッケージ+継承可 | protected int age; |
7️⃣ その他
| 予約語 | 用途 | 例 |
|---|---|---|
abstract | 抽象クラス・抽象メソッド | abstract class Shape{} |
assert | デバッグ用条件 | assert x>0; |
enum | 列挙型 | enum Color{RED, BLUE}; |
import | クラス読み込み | import java.util.*; |
package | パッケージ宣言 | package mypkg; |
native | ネイティブメソッド | native void method(); |
strictfp | 浮動小数点標準化 | strictfp class MyClass{} |
goto, const | 使用禁止 | – |
return | メソッドの戻り値 | return 5; |
instanceof | 型確認 | if(obj instanceof String){} |
synchronized | 排他制御 | synchronized(this){} |
覚え方のコツ
- 条件分岐・ループ →
if, else, switch, for, while, do, break, continue - クラス・型 →
class, interface, extends, implements, this, super - 型 →
int, double, boolean, char, float, long, short, byte, void - 例外 →
try, catch, finally, throw, throws - アクセス制御 →
public, private, protected, static, final
💡 これを使えば、初心者でも「どの単語が予約語で使えないか」「用途が何か」を一目で理解できます。
