Skip to main content

1.7 Java Keywords

In Java, keywords are reserved words that have a predefined meaning in the language. These keywords cannot be used as identifiers (names for variables, classes, methods, etc.). Java 8 introduced new keywords along with existing ones that form the foundation of the language.

Java Keywords Table

Below is a table listing all the important keywords in Java, along with a brief description of each:

KeywordDescription
abstractDeclares an abstract class or method.
assertUsed for debugging purposes to make an assertion.
booleanDeclares a variable as a boolean (true/false).
breakExits a loop or switch statement prematurely.
byteDeclares a variable as an 8-bit integer.
caseDefines a branch in a switch statement.
catchHandles exceptions thrown by the try block.
charDeclares a variable as a character.
classDeclares a class.
constNot used, reserved for future use.
continueSkips the current iteration of a loop and proceeds to the next one.
defaultDefines the default block in a switch statement or a default method in an interface (Java 8).
doDefines a block of code to be executed once before condition checking.
doubleDeclares a variable as a double-precision floating-point number.
elseSpecifies a block of code to execute if the if condition is false.
enumDeclares an enumeration, which is a fixed set of constants.
extendsIndicates that a class inherits from a superclass.
finalPrevents a class from being subclassed, a method from being overridden, or a variable from being modified.
finallyExecutes a block of code after a try-catch block, regardless of the outcome.
floatDeclares a variable as a floating-point number.
forDeclares a loop that repeats a block of code a set number of times.
gotoNot used, reserved for future use.
ifExecutes a block of code if a condition is true.
implementsIndicates that a class implements an interface.
importImports other Java packages or classes into your code.
instanceofTests whether an object is an instance of a particular class or interface.
intDeclares a variable as an integer.
interfaceDeclares an interface, a reference type in Java.
longDeclares a variable as a 64-bit integer.
nativeSpecifies that a method is implemented in native code using JNI.
newCreates new objects.
nullRepresents the null value, indicating no object.
packageDefines a namespace for a group of related classes.
privateRestricts access to the class, method, or variable within its own class.
protectedRestricts access to the class, method, or variable within its own package and subclasses.
publicAllows the class, method, or variable to be accessed from any other class.
returnExits from a method and optionally returns a value.
shortDeclares a variable as a 16-bit integer.
staticBelongs to the class rather than instances of the class.
strictfpUsed to restrict floating-point calculations to ensure portability.
superRefers to the parent class or constructor.
switchSelects one of many code blocks to execute.
synchronizedControls access to a method or block of code by multiple threads.
thisRefers to the current instance of a class.
throwThrows an exception.
throwsDeclares that a method may throw exceptions.
transientPrevents serialization of a field.
tryDefines a block of code to test for exceptions.
voidSpecifies that a method does not return any value.
volatileIndicates that a variable's value may be changed by different threads.
whileDefines a loop that repeats a block of code as long as a condition is true.

Conclusion

Understanding Java keywords is crucial for mastering the language, as they define the structure and flow of your programs. Java 8 brought powerful new features, but the core keywords remained the same, allowing developers to write expressive and modern Java code.