The Java Keywords

There are 50 unique keywords defined in the Java language that are used for some internal process or represent some predefined actions.

abstract continue for new switch
assert default goto package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp volatile
const float native super while

These keywords in java are uniquely defined, and these are case sensitive. Keywords cannot be used as an identifier, such as they cannot be used as names for a variable, class, or method.

Some keywords were reserved in java, such as true, false, null, const, and goto. We may not use these keywords for the name of variables, classes, and so on.

Keywords are explained below:

Keywords Description
abstract It is used to declare an abstract class that provides the implementation of the interface.
boolean It is used to declare a variable as a boolean type. It only holds true and false values.
break It breaks the current flow of the code (loop or switch statement).
byte This keyword declares a variable that can hold 8-bit data values.
case It is used with the switch statement to define different cases.
catch This keyword is used to catch the exceptions generated by try statements.
char It declares a variable that can hold unsigned 16-bit Unicode characters
class It is used to declare a class.
continue This keyword is used to continue the loop (current flow of the program and skips the remaining code at the specified condition).
default The default keyword is used to define the default block of code in a switch statement.
do This keyword is used in the control statement to declare a loop.
double This keyword declares a variable that can hold a 64-bit floating-point number.
else It is used to indicate the alternative branches in an “if” statement.
enum This keyword defines a fixed set of constants. This constructor is always private or default.
extends It indicates that a class is derived from another class or interface.
final It is used to indicate that a variable holds a constant value. The value of the variable always remains constant if we declare it with the final keyword.
finally It indicates a block of code in a try-catch structure. It is always executed whether an exception is handled or not.
float This keyword declares a variable that can hold a 32-bit floating-point number.
for It executes a set of instructions or functions repeatedly when some conditions become true. If the number of iteration is fixed, it is recommended to use “for loop”.
if It tests the condition and executes the “if block” if the condition is true.
implements It is used to implement an interface.
import This keyword makes classes and interfaces available and accessible to the current source code.
instanceof It tests whether the object is an instance of the specified class or implements an interface.
int It is used to declare a variable that can hold a 32-bit signed integer.
interface It declares an interface. It can have only abstract methods.
long It declares a variable that holds a 64-bit integer.
native This keyword specifies that a method is implemented in native code using JNI (Java Native Interface).
new It creates a new object.
null This keyword indicates that a reference does not refer to anything. It removes the garbage value.
package It declares a Java package that includes the classes.
private It is an access modifier that indicates that a method or variable may be accessed only in the class where it was declared.
protected It is an access modifier that can be accessed within the package and outside the package but through inheritance only. It can’t be applied to the class.
public It is an access modifier that is used to indicate that an item can be accessed anywhere. It has the widest scope among all other modifiers.
return This keyword is used to return from a method when its execution is complete.
short This keyword declares a variable that can hold a 16-bit integer.
static This keyword indicates that a variable or method is a class method. It is used for memory management mainly.
strictfp It is used to restrict the floating-point calculations to ensure the portability of the code.
super This keyword is a reference variable that is used to refer to the parent class object. It can also be used to invoke an immediate parent class method.
switch It contains a switch statement which executes code based on test value. It tests the equality of a variable against multiple values.
synchronized This keyword is used to specify the critical sections or methods in a multithreaded code.
this It refers to the current object in a method or constructor.
throw It explicitly throws an exception. The “throw” keyword is used to throw a custom exception, followed by an instance.
throws It declares an exception. A checked exception can be piped with throws.
transient This keyword is used in serialization. If we define any data member as transient, then it can’t be serialized.
try It starts a block of code that will be tested for exceptions. It must be followed by either catch or finally block.
void The void keyword specifies that a method does not have a return value.
volatile This keyword is used to indicate that a variable may change asynchronously.
while It starts a loop that iterates a part of the program number of times.

Pin It on Pinterest

Share This