What is a keyword?

A keyword is a reserved term or words of any programming language. Java has around 57 keywords, each keyword is having a special meaning, purpose, and use.

A Reserved keyword means you are not allowed to use it as variables, methods, classes, or as any other identifier. A compile-time error will occur if you try to use any of them.

Java Keywords

KeywordDescription
abstractUsed to implement abstraction in Java.
assertUsed to declare an expected boolean condition in a program.
booleanUsed to declare a variable as a type of boolean.
breakIt breaks the current flow of the program at a specified condition inside loops or inside the switch case construct.
byteUsed to declare a variable that can hold 8-bit data values.
caseUsed with the switch keyword, the switch-case construction is a flow control structure that tests the value of a variable against a list of values.
catchIt is used together with a try block. The statements in the catch block specify what to do if the try block throws a specific type of exception.
charUsed to declare a variable as a character type. A char variable represents a single character.
classUse of this keyword is to declare a class or define a class.
continueSkips remaining statements inside the loop and resume the loop.
defaultThe default keyword can be used in two different ways in Java. The first way is to add a default ‘case’ in switch statements and another way is to add default methods in interfaces since Java 8.
doUsed with while keyword in the do-while loop. The do-while loop is looping functionally similar to the while loop.
doubleIt is used to declare a variable that can hold a 64-bit floating number.
elseUsed with if keyword to create an if-else statement, else block executes when if expression evaluated false.
enumUsed to declare a new enumeration type. Enum in Java is a data type that contains a fixed set of constants.
exportsThis keyword is introduced in Java 9, it is used to export a package with a module.
extendsUsed to declare a class as a subclass of another class.
finalThis keyword is to make a variable as a constant, it restricts method overriding, inheritance.
finallyUsed with try catch block, finally block is an optional part of the try block. The finally block will be evaluated whether try block throws an exception or not.
floatUsed to declare a data type that can hold a 32-bit floating-point number.
forUsed to create for-loop in Java.
ifUsed to check if some given condition is true or false.
implementsThis keyword specifies that a class implements an interface.
importUsed to import/add built-in or user-defined packages into your Java source file.
instanceofUsed to check whether the given object is an instance of a particular class or not.
intUsed to declare a variable that can hold a 32-bit integer number.
interfaceUsed to declare an interface.
longUsed to declare a variable that can hold a 64-bit integer number
moduleThis keyword is introduced in Java 9, it is used to declare a module inside a Java application
nativeUsed in method declarations to specify that the method is implemented with native (platform-specific) code such as C or C++.
newUsed to create a new instance (object) of a class.
packageDeclares a Java package, which is used to group similar classes and interfaces.
privateUsed to declare a method, field or inner class as a private member of a class. When we declare something private that means this can only be accessed within the declared class itself.
protectedUsed to declare a method, field or inner class as a protected member of a class. When we declare something protected that means this can be accessed only by the subclasses in other package or any class within the package of the protected members’ class.
publicUsed to declare a class, method or field as a public member of a class. Which can be accessed by the members of any class.
requiresThis keyword is introduced in Java 9, it is used to specify the required libraries within a module.
returnUsed to finish and return value from a method.
shortUsed to declare a field that can hold a 16-bit integer
staticThe static keyword is used to declare fields, methods, or inner classes as class fields.
strictfpUsed to restrict the precision and rounding of floating point calculations to ensure portability.
superThis keyword is used in method or constructor, to access members of a class inherited by the class in which it appears.
switchThe switch keyword is used with the case statement and default to create a switch statement. The switch-case construction is a flow control structure that tests the value of a variable against a list of values.
synchronizedUsed in method or code block declarations to acquire an object’s mutex lock while the current thread is executing the code.
thisUsed to represent an instance of the class in which it appears.
throwCreates an exception
throwsUsed in method declarations to specify exceptions that are not handled within the method and then passed to the upper levels of the program.
transientSpecifies that the variable is not part of the object’s persistent state
tryDefine a block of statements that include exception handling.
voidUsed to declare that the method does not return a value.
volatileUsed in field declarations to specify that variables are being changed asynchronously by concurrently executing threads.
whileThe while keyword is used to create a while loop.
trueA boolean literal value.
nullA reference literal value.
falseA boolean literal value.
constReserved keyword by Java, but not in use.
gotoReserved keyword by Java, but not in use.