Open In App

Java Keywords

Last Updated : 25 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In Java, Keywords or Reserved words are the words in a language that are used for some internal process or represent some predefined actions. These words are therefore not allowed to use as variable names or objects. 

If we do we will get a compile-time error as shown below as follows:

Example of Java Programming Keywords

Java
// Java Program to Illustrate What If We use the keywords as
// the variable name

// Driver Class
class HelloWorld {
    // Main Function
    public static void main(String[] args)
    {
        // Note "this" is a reserved
        // word in java
        String this = "Hello World!";
        System.out.println(this);
    }
}

Output:

./HelloWorld.java:6: error: not a statement
String this = "Hello World!"; System.out.println(this);
^
./HelloWorld.java:6: error: ';' expected
String this = "Hello World!"; System.out.println(this);
^
2 errors

Java Keywords List

Java contains a list of keywords or reserved words which are also highlighted with different colors be it an IDE or editor in order to segregate the differences between flexible words and reserved words. They are listed below in the table with the primary action associated with them.

KeywordUsage
abstractSpecifies that a class or method will be implemented later, in a subclass 
assertAssert describes a predicate placed in a Java program to indicate that the developer thinks that the predicate is always true at that place.
booleanA data type that can hold True and False values only 
breakA control statement for breaking out of loops.
byteA data type that can hold 8-bit data values 
caseUsed in switch statements to mark blocks of text
catchCatches exceptions generated by try statements
charA data type that can hold unsigned 16-bit Unicode characters
classDeclares a new class
continueSends control back outside a loop 
defaultSpecifies the default block of code in a switch statement
doStarts a do-while loop
doubleA data type that can hold 64-bit floating-point numbers
elseIndicates alternative branches in an if statement 
enumA Java keyword is used to declare an enumerated type. Enumerations extend the base class.
extendsIndicates that a class is derived from another class or interface 
finalIndicates that a variable holds a constant value or that a method will not be overridden
finallyIndicates a block of code in a try-catch structure that will always be executed
floatA data type that holds a 32-bit floating-point number 
forUsed to start a for loop
ifTests a true/false expression and branches accordingly
implementsSpecifies that a class implements an interface 
importReferences other classes
instanceofIndicates whether an object is an instance of a specific class or implements an interface 
intA data type that can hold a 32-bit signed integer 
interfaceDeclares an interface
longA data type that holds a 64-bit integer
nativeSpecifies that a method is implemented with native (platform-specific) code 
newCreates new objects 
nullThis indicates that a reference does not refer to anything 
packageDeclares a Java package
privateAn access specifier indicating that a method or variable may be accessed only in the class it’s declared in
protectedAn access specifier indicating that a method or variable may only be accessed in the class it’s declared in (or a subclass of the class it’s declared in or other classes in the same package)
publicAn access specifier used for classes, interfaces, methods, and variables indicating that an item is accessible throughout the application (or where the class that defines it is accessible)
returnSends control and possibly a return value back from a called method 
shortA data type that can hold a 16-bit integer 
staticIndicates that a variable or method is a class method (rather than being limited to one particular object)
strictfpA Java keyword is used to restrict the precision and rounding of floating-point calculations to ensure portability.
superRefers to a class’s base class (used in a method or class constructor) 
switchA statement that executes code based on a test value 
synchronizedSpecifies critical sections or methods in multithreaded code
thisRefers to the current object in a method or constructor 
throwCreates an exception 
throwsIndicates what exceptions may be thrown by a method 
transientSpecifies that a variable is not part of an object’s persistent state
tryStarts a block of code that will be tested for exceptions 
voidSpecifies that a method does not have a return value
volatileThis indicates that a variable may change asynchronously
whileStarts a while loop

Important Points on Java Keywords

  • The keywords const and goto are reserved, even though they are not currently in use.
  • Currently, they are no longer supported in Java.
constReserved for future use
gotoReserved for future use

FAQs on Java Programming Keywords

1. What are the keywords of Java?

Keywords are the reserved words in Java having certain meanings. These words are not allowed to use as variable names or object names.

2. How many keywords are in Java?

There are 67 Keywords in Java.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads