Keywords
- In Java, keywords are reserved words that have predefined meanings and functions inside the language. They are necessarily to the syntax and cannot be utilized as identifiers, such as variable names, method names, or class names.
- Keywords are the basic or fundamental words of any programming language.
- Each keywoard will be having separate meaning and functionality.
- Java is a case sensitive programming language. Hence keyword should be written in lowercase or small case.
- Keywords are already declared by Java language itself. hence, these words are called as a predefined words or reserved words
- In Java there are 52+ keywords.
- Java keywords are essential building blocks of the Java programming language.
- They have predefined meanings and functions, and you cannot use them for naming variables, methods, classes, or identifiers.
- These keywords enable various functionalities such as defining data types, controlling program flow, and implementing object-oriented features.
List of Java Keywords
Java has a total of 52 reserved keywords as of Java SE 17, which are categorized as follows

1. Control Flow Keywords
These keywords are used for decision-making, looping, and controlling program flow.
- if, else
- switch, case, default
- for, while, do
- break, continue
- return
2. Access Modifiers
These keywords indicate the scope and availability of variables, methods, and classes.
- private: Restricts access to individuals inside the same class as it were.
- protected: Permits access to individuals inside the same package or subclasses.
- public: Gives access to individuals from any class.
3. Class, Object, and Interface Keywords
These are used to define classes, interfaces, and objects in Java.
- class, interface, enum, record
- extends, implements
- this, super
4. Exception Handling Keywords
These keywords are used for managing exceptions and error handling.
- try, catch, finally
- throw, throws
5. Primitive Data Types
These are keywords for defining primitive data types in Java.
- int, float, double, char, byte, short, long, boolean
6. Other Keywords
- void: Specifies that a method does not return a value.
- static: Indicates that a member belongs to the class rather than an instance.
- final: Used to declare constants, prevent inheritance, or prevent method overriding.
- abstract: Used to declare abstract classes and methods.
- synchronized: Ensures thread security.
- volatile: Prevents threads from caching variables locally.
- transient: Prevents serialization of a variable.
- native: Specifies that a method is implemented in native (non-Java) code.
7. Reserved for Future Use
These keywords are reserved but not currently used in the language:
- const, goto
8. Null-Related Keywords
- null: Represents the null value.
- true, false: Represent boolean values.
9.Advanced Concepts
- Polymorphism: Accomplished using keywords like abstract, interface, abrogate, etc.
- Encapsulation: Taken care of using access modifiers like private, protected, and public.
Examples of Java Keywords in Use
1.Control Flow Example:
public class Example {
public static void main(String[] args) {
int number = 10;
if (number > 5) {
System.out.println(“The number is greater than 5.”);
} else {
System.out.println(“The number is 5 or less.”);
}
}
}
2.Defining a Class:
public class Car {
private String model;
private int speed;
public Car(String model, int speed) {
this.model = model;
this.speed = speed;
}
public void displayDetails() {
System.out.println(“Model: ” + model + “, Speed: ” + speed);
}
}
3.Using final
and static
:
public class Constants {
public static final double PI = 3.14159;
public static void main(String[] args) {
System.out.println(“Value of PI: ” + PI);
}
}
4.Exception Handling Example:
public class ExceptionExample {
public static void main(String[] args) {
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println(“Division by zero is not allowed.”);
} finally {
System.out.println(“End of program.”);
}
}
}
Examples of Use
Here’s how some of these keywords work together:
package mypackage;
import java.util.ArrayList;
public class Example extends SuperClass {
private final int MAX_COUNT = 10;
public static void main(String[] args) {
try {
for (int i = 0; i < MAX_COUNT; i++) {
System.out.println(“Count: ” + i);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println(“Execution completed.”);
}
}
}
Key Characteristics of Java Keywords
- Reserved: Cannot be used for any purpose other than their predefined functions.
- Case-Sensitive: Must always be written in lowercase.
- Integral to Syntax: Form the structure of Java code.