3/21/26, 11:46 AM Java Keyw ords - GeeksforGeeks
Courses
Search... Tutorials
Sign In
Practice
Java Tutorial Advanced Java Interview Questions Exercises Examples Quizzes Projects Cheatsheet DSA in Java Java Collection
Jobs
Java Keywords
Last Updated : 4 Dec, 2025
In Java, keywords are the reserved words that have some predefined meanings and are used by the Java
compiler for some internal process or represent some predefined actions. These words cannot be used as
identifiers such as variable names, method names, class names, or object names.
Now, let us go through a simple example before a deep dive into the article.
class Geeks {
public static void main(String[] args)
{
// Using final and int keyword
final int x = 10;
// Using if and else keywords
if(x > 10){
[Link]("Failed");
}
else {
[Link]("Successful demonstration"
+" of keywords.");
}
}
}
Output
Successful demonstration of keywords.
What Happens if we use a Variable Name same as keyword?
Using a keyword as a variable name would give error as shown below.
class Geeks
{
public static void main(String[] args)
{
String this = "Hello World!";
[Link](this);
}
}
Output:
./[Link]: error: not a statement
String this = "Hello World!";
^
./[Link]: error: ';' expected
String this = "Hello World!";
[Link] w w .[Link]/java/java-keyw ords/ 1/6
3/21/26, 11:46 AM Java Keyw ords - GeeksforGeeks
2 errors
Important Points:
The keywords const and goto are reserved, even though they are not currently used in Java.
true, false, and null look like keywords, but in actuality they are literals. However, they still can't be
used as identifiers in a program.
In Java, keywords are case-sensitive, and writing Java keywords in upper case (like IF instead of if) will
throw an error.
Java Keywords List (As of Java 21)
Java keywords are reserved words that have predefined meanings in the language. They cannot be used
as identifiers (like variable or method names).
As of Java 21, there are 53 keywords, categorized below by their usage and purpose.
1. Data Type Keywords
Used to define variable types and specify the kind of data they can hold.
Keyword Usage
boolean Defines a variable that holds true or false.
byte Defines an 8-bit signed integer.
char Defines a 16-bit Unicode character.
short Defines a 16-bit signed integer.
int Defines a 32-bit signed integer.
long Defines a 64-bit signed integer.
float Defines a 32-bit floating-point number.
double Defines a 64-bit floating-point number.
void Specifies that a method does not return any value.
2. Control Flow Keywords
Used to control the execution flow of a program, including loops, branching, and jumps.
Keyword Usage
if Executes code when a condition is true.
else Defines an alternate block when an if condition is false.
[Link] w w .[Link]/java/java-keyw ords/ 2/6
3/21/26, 11:46 AM Java Keyw ords - GeeksforGeeks
Keyword Usage
switch Selects one block of code among multiple options.
case Defines an individual branch in a switch statement.
default Defines the block executed if no case matches.
for Starts a for loop.
while Starts a while loop.
do Starts a do-while loop.
break Terminates the nearest loop or switch .
continue Skips to the next iteration of a loop.
return Exits from a method and optionally returns a value.
3. Exception Handling Keywords
Used for handling and managing runtime errors in programs.
Keyword Usage
try Defines a block of code to test for exceptions.
catch Defines a block to handle exceptions thrown by try .
finally Defines a block that always executes after try and catch .
throw Used to manually throw an exception.
throws Declares the exceptions a method can throw.
assert Tests assumptions during program execution for debugging.
4. Object-Oriented Keywords
Used to define classes, interfaces, and objects, as well as inheritance and encapsulation properties.
Keyword Usage
class Declares a class.
interface Declares an interface.
extends Indicates inheritance from a superclass.
[Link] w w .[Link]/java/java-keyw ords/ 3/6
3/21/26, 11:46 AM Java Keyw ords - GeeksforGeeks
Keyword Usage
implements Indicates that a class implements an interface.
new Creates new objects.
this Refers to the current object.
super Refers to the superclass of the current object.
abstract Declares a class or method that must be implemented in a subclass.
final Prevents inheritance, overriding, or modification.
static Declares class-level variables or methods.
sealed Restricts which classes can extend a given class.
permits Specifies the subclasses allowed to extend a sealed class.
5. Access Control Keywords
Define the visibility or accessibility of classes, methods, and variables.
Keyword Usage
public Accessible from anywhere in the program.
protected Accessible within the same package or by subclasses.
private Accessible only within the same class.
6. Package and Import Keywords
Used to organize classes and access external code.
Keyword Usage
package Defines a namespace for classes.
import Allows access to classes from other packages.
7. Multithreading and Synchronization Keywords
Used to handle concurrent execution of code and ensure thread safety.
[Link] w w .[Link]/java/java-keyw ords/ 4/6
3/21/26, 11:46 AM Java Keyw ords - GeeksforGeeks
Keyword Usage
synchronized Defines critical sections that only one thread can access at a time.
volatile Indicates that a variable may change asynchronously.
8. Memory Management and Object Serialization Keywords
Handle object persistence, garbage collection, and native method calls.
Keyword Usage
transient Excludes a variable from serialization.
native
Specifies that a method is implemented in native (non-Java) code.
9. Modifier and Utility Keywords
Define additional behaviors and precision control.
Keyword Usage
strictfp Ensures consistent floating-point calculations across platforms.
10. Reserved (Unused) Keywords
These keywords are reserved but not currently used by Java.
Keyword Usage
const Reserved for future use; not currently implemented.
goto Reserved for future use; not currently implemented.
11. Special Literals
Keyword Usage
true Represents the boolean value true.
false Represents the boolean value false.
null Represents the absence of any reference value.
Suggested Quiz 5 Questions
[Link] w w .[Link]/java/java-keyw ords/ 5/6
3/21/26, 11:46 AM Java Keyw ords - GeeksforGeeks
Which of the following is NOT a Java keyword?
A volatile
B goto
C const
D true
Login to View Explanation 1/5 < Previous Next >
Comment A Amani… Follow 140
Article Tags: Misc Java Java-keyword
Company Explore Tutorials Courses Offline Preparation
About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us Upskill AI, ML & Data Development Kolkata GfG 160
Registered Address:
Corporate Courses Science Data Science System
K 061, Tower K, Gulshan Vivante Solution DevOps Programming Design
Apartment, Sector 137, Noida,
Campus CS Core Languages
Gautam Buddh Nagar, Uttar Pradesh,
201305 Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
[Link] w w .[Link]/java/java-keyw ords/ 6/6