In Java, a keyword is a reserved word that has a predefined meaning in the language. These words are special and can’t be used as names for variables, functions, or other identifiers. Each keyword is a building block of the language, helping the Java compiler understand how to interpret the code you write.
Java keywords are case-sensitive, meaning public is different from Public or PUBLIC.
| Keyword | Description |
|---|---|
| abstract | Defines an abstract class or an abstract method that must be implemented by subclasses. |
| assert | Used for debugging; checks an assumption in the code. |
| boolean | Defines a boolean data type with values true or false. |
| break | Exits from a loop, switch, or label statement. |
| byte | Defines a data type with an 8-bit integer value. |
| case | Defines a branch in a switch statement. |
| catch | Used to handle exceptions in a try-catch block. |
| char | Defines a data type for a single character. |
| class | Defines a class, which is a blueprint for objects. |
| const | Reserved but not used in Java (historically used in older versions). |
| continue | Skips the current iteration of a loop and continues with the next iteration. |
| default | Specifies the default case in a switch statement. |
| do | Defines a loop that executes at least once before checking the condition. |
| double | Defines a data type for a double-precision floating point number. |
| else | Specifies the block of code to execute if the if condition is false. |
| enum | Defines a set of named constants. |
| extends | Indicates that a class is inheriting from a superclass. |
| final | Specifies that a variable, method, or class cannot be changed or extended. |
| finally | Defines a block of code that is always executed after try and catch. |
| float | Defines a data type for a single-precision floating point number. |
| for | Defines a loop that iterates a specific number of times. |
| goto | Reserved but not used in Java (was used in older languages). |
| if | Defines a conditional statement that executes code based on a condition. |
| implements | Indicates that a class is implementing an interface. |
| import | Imports other classes or packages into the current file. |
| instanceof | Tests whether an object is an instance of a particular class or subclass. |
| int | Defines a data type for a 32-bit integer value. |
| interface | Defines an interface, which is a contract for implementing classes. |
| long | Defines a data type for a 64-bit integer value. |
| native | Specifies that a method is implemented in native (non-Java) code. |
| new | Creates new objects or instances of classes. |
| null | Represents the null reference, which points to no object. |
| package | Defines a package, grouping related classes together. |
| private | Defines access to class members; accessible only within the same class. |
| protected | Defines access to class members; accessible within the same package or by subclasses. |
| public | Defines access to class members; accessible from any class. |
| return | Exits from a method and optionally returns a value. |
| short | Defines a data type for a 16-bit integer value. |
| static | Specifies that a variable or method belongs to the class itself, not an instance. |
| strictfp | Ensures consistent floating-point calculations across different platforms. |
| super | Refers to the superclass or parent class. |
| switch | Defines a multi-way branch statement, comparing one value to many possible values. |
| synchronized | Defines a block of code that can only be accessed by one thread at a time. |
| this | Refers to the current instance of a class. |
| throw | Used to throw exceptions manually. |
| throws | Defines the exceptions a method may throw. |
| transient | Specifies that a field should not be serialized. |
| try | Defines a block of code that might throw exceptions, which can be handled in a catch block. |
| void | Specifies that a method does not return any value. |
| volatile | Indicates that a variable may be modified by multiple threads. |
| while | Defines a loop that repeats as long as the specified condition is true. |
constandgotoare reserved keywords in Java but are not used in the language.- Keywords like
null,true, andfalseare literals in Java and have special meanings. They are technically not keywords but are often grouped with them for reference.