Keywords in Java (Reserved Words) Explained with Examples – Core Java Tutorial
Keywords in Java (Reserved Words) Explained with Examples
Learn Java — a complete guide to understanding Java keywords, their importance, rules, and usage with real examples.
What are Keywords in Java?
In Java, keywords are predefined, reserved words that have a special meaning to the Java compiler. These words are part of the Java syntax and cannot be used as identifiers (like variable or class names).
int class = 10; // ❌ Invalid: 'class' is a keyword
int number = 10; // ✅ Valid identifier
For example, class, if, for, and return are Java keywords that define how the code should behave.
Why Java Keywords Are Reserved
Java keywords are reserved to maintain consistency in the language structure. Each keyword has a predefined role, and using them for variable or method names would create confusion for the compiler.
- if – used for conditional statements
- class – defines a new class
- return – exits from a method
That’s why keywords are called reserved words — they are reserved for specific language constructs only.
Important Rules About Java Keywords
Here are some important things to remember when using Java keywords:
- All Java keywords are written in lowercase letters.
- Java is case-sensitive, so
ifandIfare not the same. - Keywords cannot be used as variable, class, or method names.
Keyword Groups in Java
To understand keywords easily, we can divide them into several groups:
**1.Primitive Data Type Keywords
byte, short, int, long, char, float, double, boolean
**2.Control Flow Keywords
if, else, switch, case, default, for, while, do, break, continue, return
**3.Access & Non-Access Modifiers
public, private, protected, static, final, abstract, synchronized, transient, volatile
**4.Object-Oriented Keywords
class, interface, extends, implements, this, super, new, instanceof
**Exception Handling & Miscellaneous
try, catch, throw, throws, finally, package, import, enum, assert, native, strictfp, void
**Reserved Words (Not Keywords)
Although not true keywords, true, false, and null are reserved words that represent Boolean and null values. You cannot use them as variable names either.
Complete Java Keywords List (Java SE 17)
Total keywords: 53 (including reserved but unused ones like const and goto)
Example keywords: abstract, assert, boolean, break, byte, case, catch, char, class, continue, default, do, double, else, enum, extends, final, finally, float, for, if, 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
Watch Full Video Tutorial
To understand these keywords visually, watch the full Bangla tutorial on YouTube:
▶ Watch on YouTube: Keywords in Java (Reserved Words) – Explained in Bangla
📌 Core Java Playlist: Watch Full Core Java Playlist on YouTube❓ Frequently Asked Questions
Q1: How many keywords are there in Java?
There are 53 keywords in Java SE 17, though some are reserved but not used (like const and goto).
Q2: Can I use keywords as variable names?
No, keywords are reserved words and cannot be used as variable, class, or method names.
Q3: Are Java keywords case-sensitive?
Yes, Java is case-sensitive. For example, if is a valid keyword but If is not.
Comments
Post a Comment