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
Keyword | Description |
---|---|
abstract | Used to implement abstraction in Java. |
assert | Used to declare an expected boolean condition in a program. |
boolean | Used to declare a variable as a type of boolean. |
break | It breaks the current flow of the program at a specified condition inside loops or inside the switch case construct. |
byte | Used to declare a variable that can hold 8-bit data values. |
case | Used 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. |
catch | It 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. |
char | Used to declare a variable as a character type. A char variable represents a single character. |
class | Use of this keyword is to declare a class or define a class. |
continue | Skips remaining statements inside the loop and resume the loop. |
default | The 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. |
do | Used with while keyword in the do-while loop. The do-while loop is looping functionally similar to the while loop. |
double | It is used to declare a variable that can hold a 64-bit floating number. |
else | Used with if keyword to create an if-else statement, else block executes when if expression evaluated false. |
enum | Used to declare a new enumeration type. Enum in Java is a data type that contains a fixed set of constants. |
exports | This keyword is introduced in Java 9, it is used to export a package with a module. |
extends | Used to declare a class as a subclass of another class. |
final | This keyword is to make a variable as a constant, it restricts method overriding, inheritance. |
finally | Used 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. |
float | Used to declare a data type that can hold a 32-bit floating-point number. |
for | Used to create for-loop in Java. |
if | Used to check if some given condition is true or false. |
implements | This keyword specifies that a class implements an interface. |
import | Used to import/add built-in or user-defined packages into your Java source file. |
instanceof | Used to check whether the given object is an instance of a particular class or not. |
int | Used to declare a variable that can hold a 32-bit integer number. |
interface | Used to declare an interface. |
long | Used to declare a variable that can hold a 64-bit integer number |
module | This keyword is introduced in Java 9, it is used to declare a module inside a Java application |
native | Used in method declarations to specify that the method is implemented with native (platform-specific) code such as C or C++. |
new | Used to create a new instance (object) of a class. |
package | Declares a Java package, which is used to group similar classes and interfaces. |
private | Used 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. |
protected | Used 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. |
public | Used to declare a class, method or field as a public member of a class. Which can be accessed by the members of any class. |
requires | This keyword is introduced in Java 9, it is used to specify the required libraries within a module. |
return | Used to finish and return value from a method. |
short | Used to declare a field that can hold a 16-bit integer |
static | The static keyword is used to declare fields, methods, or inner classes as class fields. |
strictfp | Used to restrict the precision and rounding of floating point calculations to ensure portability. |
super | This keyword is used in method or constructor, to access members of a class inherited by the class in which it appears. |
switch | The 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. |
synchronized | Used in method or code block declarations to acquire an object’s mutex lock while the current thread is executing the code. |
this | Used to represent an instance of the class in which it appears. |
throw | Creates an exception |
throws | Used in method declarations to specify exceptions that are not handled within the method and then passed to the upper levels of the program. |
transient | Specifies that the variable is not part of the object’s persistent state |
try | Define a block of statements that include exception handling. |
void | Used to declare that the method does not return a value. |
volatile | Used in field declarations to specify that variables are being changed asynchronously by concurrently executing threads. |
while | The while keyword is used to create a while loop. |
true | A boolean literal value. |
null | A reference literal value. |
false | A boolean literal value. |
const | Reserved keyword by Java, but not in use. |
goto | Reserved keyword by Java, but not in use. |