Jump to content

List of Java keywords

From Alfawiki
Adapted from the English Wikipedia article List of Java keywords, available under CC BY-SA 4.0Updated 9 August 2025
Java keywords
Company typeProgramming language feature
IndustrySoftware development
ProductsReserved words in Java language syntax

In the Java language, a keyword refers to one of the 68 reserved words predefined by the language's syntax. These keywords cannot serve as names for variables, methods, classes, or other identifiers. Among these, 17 are reserved only in specific contexts and may occasionally be used as identifiers. Most integrated development environments visually distinguish keywords for easier recognition.

Keywords

The following list consists of keywords that are prohibited from being used as identifiers.

_
Introduced in Java 9, the underscore character is now a keyword and cannot be utilized as a variable identifier.
abstract
Used to declare methods lacking an implementation; such methods require the enclosing class to be abstract and non-instantiable. Subclasses must provide implementations for abstract methods.
assert (added in J2SE 1.4)
Denotes a runtime condition expected to be true; if it evaluates to false, program execution halts. Assertions are disabled by default but can be activated via command-line options or programmatically.
boolean
Defines variables or methods that yield true or false values. The default value is false.
break
Ends the current loop's execution or exits a switch statement prematurely.
byte
Declares variables or method return types as 8-bit signed integers.
case
Marks specific statements within a switch block to match against given values.
catch
Specifies code blocks that handle exceptions following a try segment.
char
Declares variables capable of holding single characters from the source code's character set.
class
Defines an object blueprint including fields, methods, inner classes, interfaces, and superclass references. If no superclass is specified, it defaults to . Also used with Class.class syntax to obtain a Class object.
continue
Skips to the next iteration of the current or labeled loop.
default
Indicates statements to execute when no matching case exists in a switch. Additionally used in annotations and since Java 8 can provide default method implementations within interfaces.
do
Creates a loop that executes its body before evaluating a boolean condition; repeats while the condition holds true.
double
Declares variables or method returns as 64-bit IEEE 754 floating-point numbers.
else
Works alongside if, providing alternative execution when the condition evaluates to false.
enum (added in J2SE 5.0)
Defines enumerated types that extend .
extends
Specifies a superclass for classes or superinterfaces for interfaces; supports inheritance and bounds in generics.
final
Makes classes unextendable, methods non-overridable, and variables immutable after initialization.
finally
Designates code that runs after try/catch, regardless of whether exceptions were thrown or returns occurred.
float
Declares variables or method returns as 32-bit IEEE 754 floating-point numbers.
for
Creates loops with initialization, condition checking, and increment expressions. Since J2SE 5.0, supports enhanced "foreach" loops iterating over arrays or iterable objects.
if
Evaluates a boolean expression to conditionally execute code blocks; often combined with else for alternative paths.
implements
Indicates which interfaces a class adopts, inheriting their abstract methods and types.
import
Allows inclusion of classes or packages without requiring fully qualified names; since J2SE 5.0, supports importing static members and Java modules.
instanceof
A binary operator that checks whether an object is compatible with a specified class or interface at runtime, returning a boolean result.
int
Declares variables or method returns as 32-bit signed integers.
interface
Defines interfaces containing abstract and default methods along with constants; classes implement these to achieve multiple inheritance alternatives.
long
Declares variables or method returns as 64-bit signed integers.
native
Marks methods implemented outside Java source code, typically using other programming languages.
new
Creates new instances of classes or arrays, explicitly defining runtime types and maintaining separation between method and class namespaces.
package
Gathers related classes and interfaces under one namespace; declared at the beginning of source files.
private
Makes members accessible solely within their defining class.
protected
Makes members accessible within their class, subclasses, or other classes in the same package.
public
Makes classes, methods, or fields accessible from any other class.
return
Terminates method execution and optionally sends a value back to the caller.
short
Declares variables or method returns as 16-bit signed integers.
static
Makes fields, methods, or inner classes belong to the class itself rather than instances; static methods can only access static members. Nested static classes behave similarly to top-level classes in terms of behavior.
[inheritance (object-oriented programming)|super]
Accesses inherited members from the superclass; also forwards constructor calls to superclass constructors; specifies lower bounds in generics declarations.
[switch statement|switch]
Evalues expressions against multiple cases to execute matching code blocks; supports pattern matching and optional default cases; recent versions support switch expressions using yield.
[mutual exclusion|synchronized]
Synchronized methods or blocks acquire an object's lock during execution to ensure thread safety; locks are released upon completion. Only methods and blocks—not fields or entire classes—can be synchronized.
[this (Java)|this]
References the current object instance for accessing members or forwarding constructor calls within the same class context.
[exception handling syntax#Java|throw]
Raises exceptions that propagate up the call stack until caught by enclosing handlers; if uncaught, passed to the thread's default exception handler.
[exception handling syntax#Java|throws]
Declares exceptions that a method may propagate; all checked exceptions must be declared unless they derive from RuntimeException subclasses.
[transient (computer programming)|transient]
Makes instance fields excluded from default serialization processes; such fields reset to default values upon deserialization unless custom serialization is implemented.
[exception handling syntax#Java|try]
Binds exception handling segments with optional [catch], executed when exceptions occur, and optional [finally], which always runs after try/catch blocks finish. A try block requires at least one catch or finally clause to be valid.
[void type|void]
Makes methods return no value upon completion.
[volatile variable|volatile]
Makes field updates immediately visible across threads by forcing reads/writes directly from main memory instead of CPU caches; applicable only to fields—not methods, classes, local variables, or parameters.
[do while loop|while]
Casts loops that repeatedly execute while a boolean condition remains true; forms both while loops and do-while loops when combined with [do].

Reserved Identifiers

The following identifiers function as contextual keywords and are limited to specific scenarios:

exports
Defines which packages within a module are accessible to other modules.
module
Declares a module, which groups related packages and resources to encapsulate and expose a library's public interface.
non-sealed
Permits a class or interface that extends a sealed class to be further subclassed by other, unspecified classes.
open
Grants reflective access to all classes in a package from other modules.
opens
Allows selective reflective access to a particular package for specified modules.
permits
Lists the classes authorized to extend a sealed class.
provides
Indicates that a module supplies an implementation for a service interface.
record
A specialized class designed as an immutable data carrier, which automatically implements .equals(), .hashCode(), and .toString() methods.
requires
Specifies dependencies on other modules within module declarations.
sealed
Limits subclassing or implementation of a class or interface exclusively to permitted classes.
to
Used alongside opens to designate the module allowed reflective access to the package.
transitive
Applied with requires, this keyword propagates dependencies to modules that depend on the current one.
uses
Declares that the module consumes services provided externally.
var
A reserved identifier disallowed as a type name since Java 10; enables variable declaration without explicit typing by relying on compiler inference.
when
Introduces an extra condition within case statements.
with
Specifies the implementation of a service offered by the module, used in conjunction with provides.
yield
Assigns values within switch expressions through labeled statement blocks.

Reserved Words for Literal Values

The following terms denote literal values recognized by the language:

true
A boolean literal representing truth.
false
A boolean literal representing falsehood.
null
A literal representing a null reference.

Unused

These keywords are reserved but currently lack any operational role:

const
Reserved in Java but unused. In other programming languages, const declares constants; Java employs final for this purpose.
goto
Reserved yet unused in Java. In other languages, goto facilitates jumps to labeled code sections.
strictfp (introduced in J2SE 1.2)
Reserved but now deprecated. It formerly controlled floating-point precision and rounding behavior for consistency across platforms.

See also

External links