In the Java programming language, a keyword is any one of 68 reserved words[1] that have a predefined meaning in the language. Because of this, programmers cannot use keywords in some contexts, such as names for variables, methods, classes, or as any other identifier.[2] Of these 68 keywords, 17 of them are only contextually reserved, and can sometimes be used as an identifier, unlike standard reserved words. Due to their special functions in the language, most integrated development environments for Java use syntax highlighting to display keywords in a different colour for easy identification.
The following words are keywords and cannot be used as identifiers under any circumstances.
_
abstract
assert
boolean
bool
break
switch
byte
case
default
catch
try
finally
char
class
Object
Class.class
Class
String.class
new String().getClass()
continue
do
while
true
false
double
else
if
enum
Enum
extends
final
return
float
for
Iterable
implements
import
static
import module
instanceof
int
interface
static final
long
native
new
package
private
protected
public
short
super
yield
synchronized
this
throw
throws
RuntimeException
transient
void
volatile
The following identifiers are contextual keywords, and are only restricted in some contexts:
exports
module
non-sealed
open
opens
permits
provides
record
.equals()
.hashCode()
.toString()
requires
sealed
to
transitive
uses
var
when
with
case L:
The following words refer to literal values used by the language.
null
The following words are reserved as keywords, but currently have no use or purpose.
const
goto
strictfp