Java keywords are reserved words that have a predefined meaning in the Java language. These words cannot be used as variable names, class names, or identifiers because they are part of Java’s syntax and core functionality.
Keywords are used to declare data types, control program flow, handle exceptions, define classes, and manage access control.
class – used to declare a classpublic, private, protected – access modifiersstatic – belongs to class rather than objectif, else, switch – decision makingfor, while – looping
// Example showing usage of Java keywords
public class KeywordDemo {
public static void main(String[] args) {
int number = 10;
if (number > 5) {
System.out.println("Number is greater than 5");
}
}
}
In this example, keywords like public, class, static, void, int, and if are used to define the structure and logic of the Java program.
for and while loops