Java possesses a collection of reserved words known as keywords, which cannot be utilized as identifiers for variables, methods, classes, or any other programming constructs.
Keyword |
Description |
abstract |
An abstract class, a non-access modifier used for classes and methods, cannot be instantiated directly; it must be inherited by another class. Abstract methods within an abstract class lack a body and must be implemented by subclasses |
assert |
For the purpose of debugging. |
boolean |
A boolean data type, capable of storing only true or false values. |
break |
Terminates the execution of a loop or a switch block. |
byte |
A byte data type, capable of storing whole numbers within the range of -128 to 127. |
case |
Identifies a block of code within switch statements. |
catch |
Handles exceptions thrown by try statements. |
char |
A char data type, utilized for storing a single character. |
class |
Declares a class. |
continue |
Proceeds to the next iteration of a loop. |
const |
Specifies a constant. Deprecated; use final instead. |
default |
Specifies the default block of code within a switch statement. |
do |
Employed in conjunction with while to construct a do-while loop. |
double |
A double data type, capable of storing decimal numbers ranging from 1.7e−308 to 1.7e+308. |
else |
Employed in conditional statements. |
enum |
Declares an enumerated (unchangeable) type. |
exports |
Exports a package within a module. Introduced in Java 9. |
extends |
Indicates inheritance from another class; extends a class. |
final |
A non-access modifier applied to classes, attributes, and methods, rendering them unmodifiable (preventing inheritance or overriding). |
finally |
Utilized with exceptions, a block of code that executes regardless of whether an exception occurs or not. |
float |
A float data type, capable of storing decimal numbers ranging from 3.4e−038 to 3.4e+038. |
for |
Generate a for loop. |
go to |
Deprecated and non-functional. |
if |
Creates a conditional statement. |
implements |
Implements an interface. |
import |
Utilized to import a package, class, or interface. |
instance of |
Verifies whether an object is an instance of a particular class or interface. |
int |
An int data type, capable of storing whole numbers within the range of -2147483648 to 2147483647. |
interface |
Utilized to declare an interface, a special type of class that exclusively contains abstract methods. |
long |
A long data type, capable of storing whole numbers within the range of -9223372036854775808 to 9223372036854775807. |
module |
Specifies a module declaration. Introduced in Java 9. |
native |
Specifies that a method is not implemented in the current Java source file but in another language. |
new |
Instantiates new objects. |
package |
Defines a package. |
private |
An access modifier applied to attributes, methods, and constructors, restricting their accessibility to only within the declared class. |
protected |
An access modifier applied to attributes, methods, and constructors, allowing access within the same package and by subclasses. |
public |
An access modifier applied to classes, attributes, methods, and constructors, granting accessibility to any other class. |
requires |
Defines required libraries within a module. Introduced in Java 9. |
return |
Concludes the execution of a method, optionally returning a value from the method. |
short |
A short data type, capable of storing whole numbers within the range of -32768 to 32767. |
static |
A non-access modifier applied to methods and attributes. Static methods/attributes can be accessed without instantiating a class. |
strictfp |
Control the precision and rounding of floating-point calculations. |
super |
Refers to superclass (parent) objects. |
switch |
Chooses one of multiple code blocks to execute. |
synchronized |
A non-access modifier, specifying that methods can only be accessed by one thread at a time. |
this |
Refers to the current object within a method or constructor. |
throw |
Defines a custom error. |
throws |
Specifies which exceptions may be thrown by a method. |
transient |
A non-access modifier indicating that an attribute is not part of an object’s persistent state. |
try |
Constructs a try…catch statement. |
var |
Declares a variable. Introduced in Java 10. |
void |
Specifies that a method should not have a return value. |
volatile |
Indicates that an attribute is not cached thread-locally and is consistently read from the “main memory”. |
while |
Generates a while loop. |
Note that although “true”, “false”, and “null” are not keywords, they are considered literals and reserved words that cannot be utilized as identifiers.