Reserved Keywords in Java

In every programming language, there exists a set of words that is restricted to use for naming any variable/class/object/method. The reason for such restriction is that they have a special meaning and represent some pre-defined internal process/action. This set of words are called reserved keywords. Java gives a compile-time error in case we use any reserved keyword for naming.

There are 51 reserved keywords in java. Let us look into them (alphabetical order) to have an overview of their utility in java.

Keywords Description
abstract When abstract is used with classes, it indicates that class cannot be instantiated. When abstract is used with methods, the class containing it must also be abstract. The abstract method is mandatory to be implemented in the child class. It is not used with any constructor or variable.
assert assert is used to describe the predicate statement in java. The return is boolean and if the assertion evaluates to false, the execution aborts.
boolean As discussed earlier, it is a primitive data type. It is used to create a variable, define a return type of any method. Refer to our previous lecture on Java Data types.
break break is used to end the current loop
byte As discussed earlier, it is a primitive data type. It is used to create a variable, define a return type of any method. Refer to our previous lecture on Java Data types.
case This is a part of control statements. It comes with a switch block, where the expression is evaluated and matched with a series of possible values that are preceded with the case keyword. Upon a match, the configured steps are performed.
catch This is a part of exception handling and defines the block of code upon catching a specific type of exception.
char As discussed earlier, it is a primitive data type. It is used to create a variable, define a return type of any method. Refer to our previous lecture on Java Data types.
class It is a keyword that is used to create the template of the reference data type. We have learned about several classes like Math, Arrays, String, etc.
const It is an obsolete but reserved keyword.
continue It is a keyword to take the program flow to the end without executing the instructions coming in between.
default This is a part of control statements. It comes with a switch block, where the expression is evaluated and matched with a series of possible values. If no case is matched, then the steps configured for default are performed.
do do keyword is used with while to complete the do-while syntax. It defines the set of instruction to be repeated until the expression inside while is evaluated to be false.
double As discussed earlier, it is a primitive data type. It is used to create a variable, define a return type of any method. Refer to our previous lecture on Java Data types.
else It is a part of the java control statement that serves as an alternative path when expression inside the if is evaluated false. It is also used along with if ( else if ) in order to create the chain of conditions.
enum It is used to declare the enumerated type.
extends It is a part of java inheritance. In order to reuse the features of a class that is already defined, we use the concept of inheritance which is performed using theextendskeyword. A extends B signifies all the features of B are now part of A as well. It is applicable to interfaces as well. An interface can extend another interface.
final This restricts any change/derivation to the entity. A variable defined as final can’t be changed once assigned a value. A final method cannot be overridden, and the final class cannot be a parent to any class and makes every method of it to be final.
finally This keyword is a part of exception-handling. The block defined as finally is certain to be executed regardless of any exception to occur/caught/handled.
float As discussed earlier, it is a primitive data type. It is used to create a variable, define a return type of any method. Refer to our previous lecture on Java Data types.
for for is a keyword used to define the for loop. It specifies the initialization, the expression whose evaluation as false, defines the exit condition, and the manipulation of the initialized variables after each cycle.
goto It is an obsolete but reserved keyword.
if It tests the java expression and upon evaluations decides the block of code to be executed.
implements It specifies that a class is implementing an Interface.
import It is used to link the predefined/user-defined libraries to be utilized.
int As discussed earlier, it is a primitive data type. It is used to create a variable, define a return type of any method. Refer to our previous lecture on Java Data types.
interface A keyword that is used to define an interface (alternative to abstract class).
long As discussed earlier, it is a primitive data type. It is used to create a variable, define a return type of any method. Refer to our previous lecture on Java Data types.
native It is an indicator that, the method is implemented with the platform-specific code.
new It is a keyword that is used to instantiate a new object of the class. This is used to implicitly call the constructor of a class.
null It refers that the variable is not referring to anything.
package It is used to declare a package for creation.
private It is an access specifier that defines the variable/method/ class/interface defined as such, is accessible only inside the class
protected It is an access specifier that defines the variable/method/ class/interface defined as such, are accessible only inside the class and its child classes.
public It is an access specifier that defines the variable/method /class/interface defined as such, is accessible throughout the application.
return It is the keyword that is used to return a value from the method
short As discussed earlier, it is a primitive data type. It is used to create a variable, define a return type of any method. Refer to our previous lecture on Java Data types.
static As discussed earlier, it is used to define a method/variable to the member of class instead of an instance.
strictfp The keyword used to restrict the precision/rounding of float variables.
super The keyword used to refer to the immediate parent class.Any method/variable/constructor precededwith this followed by a dot(.) specifies that this method is the version of the immediate parent.
switch This is a part of control statements. It comes with the expression which is to be evaluated and matched with a series of possible values that are preceded with case keyword. Upon a match, the configured steps are performed.
synchronized It specifies the critical section, which is applicable in multithread code.
this It is a keyword to specify the current instance. Any method/variable/constructor precededwith this followed by a dot(.) specifies that this method is the version of the current instance.
throw This keyword is used to throw an exception from the try block explicitly.
throws This keyword indicates that so and so exceptions might get thrown by the method and it is to be handled by the block calling this method.
transient It specifies that the variable is temporary and won’t be part of the instance’s session throughout.
try It specified the block of code, where an exception might occur.
void It specifies the return type of method, we the coder does not intend to return any value.
volatile It specifies that the variable is stored in the main memory, and such a variable’s value will be read from the main memory instead of CPU cache.
while It specifies the while loop. It is used to repeat a set of code on the basic of java expression. The repetition cycle continues until the expression evaluates to true.

The above is an overview of reserved keywords. The next lecture will be about Java Operators.