Java Keywords List: Which Are Keywords and Which Are Not?

The most common confusion: String, System, main and null are not reserved keywords. class, int, void, static and public are. Here is how to tell them apart.

Common quiz items: keyword or not?

IdentifierKeyword?What it actually is
classYesDeclares a class
intYesPrimitive integer type
voidYesNo return type
staticYesClass-level member modifier
publicYesAccess modifier
newYesObject creation operator
returnYesExit a method with a value
StringNoClass in java.lang
SystemNoClass in java.lang
mainNoConventional method name (not required to be named main in Java 21+)
nullNo (reserved literal)Represents absence of an object
true / falseNo (reserved literal)Boolean values
IntegerNoWrapper class in java.lang
recordNo (contextual keyword)Restricted identifier for record classes
varNo (contextual keyword)Restricted identifier for local type inference

The rule of thumb

If it appears in lowercase in every Java program and has a specific syntactic role defined by the compiler (not the standard library), it is probably a keyword. Class names from the standard library β€” String, Object, Integer, Math, System β€” are not keywords.

What happens if you use a keyword as a name?

int class = 5;    // Error: illegal start of expression
int public = 10;  // Error
String void = ""; // Error
int Int = 99;     // OK β€” Int is not a keyword (case sensitive)

Why String is not a keyword

You could theoretically write your own class named String (though you never should β€” it would conflict with java.lang.String in confusing ways). Keywords are baked into the parser; standard library class names are just names. The fact that String is auto-imported via java.lang makes it feel special, but it isn't a language keyword.

Practical impact

You will never accidentally use a real keyword as a name β€” the compiler error is immediate and clear. The distinction matters for certification exams (OCA/OCP) and for deep understanding of what the language specification versus the standard library is responsible for.