Java Keywords
In Java, keywords are reserved words that have a special meaning
in the Java language. These words cannot be used as variable names, class names,
or method names because they are already defined by the Java compiler.
Java currently has 50+ reserved keywords. Each keyword plays an important role
in defining classes, methods, variables, access control, loops, conditions,
exception handling, and object-oriented programming concepts.
1. Access Modifiers
These keywords control the visibility (access level) of classes, variables, and methods.
- public – Accessible from anywhere
- private – Accessible only within the same class
- protected – Accessible within the package and subclasses
- default – Accessible within the same package (no keyword used)
public class Test {
private int age;
}
2. Class and Object Related Keywords
- class – Defines a class
- interface – Defines an interface
- extends – Used for inheritance
- implements – Used to implement an interface
- new – Creates a new object
- this – Refers to current object
- super – Refers to parent class object
class Animal {}
class Dog extends Animal {}
Dog d = new Dog();
3. Data Type Keywords
These keywords define primitive data types in Java.
- int
- double
- float
- char
- boolean
- byte
- short
- long
int number = 10;
boolean status = true;
4. Control Flow Keywords
These keywords control the flow of execution in a program.
- if
- else
- switch
- case
- default
- for
- while
- do
- break
- continue
- return
for(int i = 0; i < 5; i++){
System.out.println(i);
}
5. Exception Handling Keywords
- try
- catch
- finally
- throw
- throws
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Error occurred");
}
6. Other Important Keywords
- static – Belongs to class rather than object
- final – Cannot be changed
- abstract – Used for abstract classes and methods
- synchronized – Used in multithreading
- volatile – Used in multithreading
- instanceof – Checks object type
final int MAX = 100;
if(obj instanceof String){
System.out.println("It is a String");
}
Why Java Keywords Are Important?
- They form the foundation of Java syntax
- Help define program structure
- Essential for writing correct code
- Important for exams and interviews
- Used in almost every Java program
Helpful Tip: Try to memorize Java keywords with examples.
Understanding their purpose is more important than just remembering the list.