What are Java Keywords?
Keywords are reserved words in Java that have special meaning to the compiler. They define the syntax and structure of Java programs and cannot be used for naming variables, methods, classes, or packages. Keywords are case-sensitive (all lowercase).
Java has a total of 52 reserved keywords, (including 3 literals: true, false, null), plus 2 reserved words (const, goto) that are not currently used but are reserved for future use.
Categories of Java Keywords
List of Java Keywords with Examples
abstract
Used to declare an abstract class or method.
abstract class Shape { }
class
Used to declare a class.
class Car { }
public
Access modifier - accessible from anywhere.
public class Demo { }
private
Access modifier - accessible only within the class.
private int age;
protected
Access modifier - accessible within package and subclasses.
protected void show() { }
static
Used to declare static members (belong to class, not instance).
static int count = 0;
final
Prevents modification of variable, method overriding, or inheritance.
final int MAX = 100;
this
Refers to the current object instance.
this.name = name;
super
Refers to the parent class object.
super.display();
if
Used for conditional branching.
if(age >= 18) { }
else
Used with if statement for alternative path.
if(a>b) { } else { }
switch
Used for multiple branch selection.
switch(day) { }
case
Used with switch statement for branches.
case 1: break;
for
Used for looping with counter.
for(int i=0;i<5;i++) { }
while
Used for conditional looping.
while(x<10) { x++; }
do
Used with while for do-while loop.
do { } while(x<10);
break
Exits a loop or switch statement.
if(i==5) break;
continue
Skips the current iteration of a loop.
if(i%2==0) continue;
return
Returns a value from a method.
return x + y;
try
Starts a block of code that may throw an exception.
try { } catch(Exception e) { }
catch
Handles exceptions thrown in try block.
catch(IOException e) { }
finally
Code that always executes after try-catch.
finally { close(); }
throw
Explicitly throws an exception.
throw new Exception();
throws
Declares exceptions a method may throw.
void read() throws IOException { }
new
Creates a new object instance.
Student s = new Student();
extends
Used for class inheritance.
class Dog extends Animal { }
implements
Used to implement an interface.
class Car implements Vehicle { }
instanceof
Checks if an object is an instance of a class.
if(obj instanceof Student) { }
interface
Used to declare an interface.
interface Drawable { }
enum
Used to declare an enumeration.
enum Days { MON, TUE, WED }
package
Used to declare a package.
package com.example;
import
Imports classes from other packages.
import java.util.*;
Things to Remember About Java Keywords
All keywords are in lowercase (e.g., class, public, static)
true, false, and null are literals (not keywords but reserved)
const and goto are reserved but not used in Java
Keywords cannot be used as identifiers (variable/class/method names)
strictfp, transient, volatile are advanced keywords
Java 9+ added module, requires, exports as restricted keywords
Best Practices for Java Keywords
Never use keywords as variable, class, or method names
Learn keywords along with their usage and code examples
Use meaningful variable names instead of reserved words
Understand the difference between keywords and identifiers
Use IDE syntax highlighting to identify keywords easily
Memorize common keywords for faster coding and interviews