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?
| Identifier | Keyword? | What it actually is |
|---|---|---|
class | Yes | Declares a class |
int | Yes | Primitive integer type |
void | Yes | No return type |
static | Yes | Class-level member modifier |
public | Yes | Access modifier |
new | Yes | Object creation operator |
return | Yes | Exit a method with a value |
String | No | Class in java.lang |
System | No | Class in java.lang |
main | No | Conventional method name (not required to be named main in Java 21+) |
null | No (reserved literal) | Represents absence of an object |
true / false | No (reserved literal) | Boolean values |
Integer | No | Wrapper class in java.lang |
record | No (contextual keyword) | Restricted identifier for record classes |
var | No (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.