Keywords and Identifiers in Java
A keyword is a word the compiler has permanently reserved — class, public, static, if, return, and roughly fifty others always mean the same fixed thing and can never be repurposed as a name. An identifier is the opposite: a name you invent for a class, variable, method, or package. Identifiers must start with a letter, underscore, or dollar sign, and can only contain letters, digits, underscores, and dollar signs after that.
Identifiers are case-sensitive, so total, Total, and TOTAL are three completely distinct names as far as the compiler is concerned. A handful of words — var, record, yield, sealed — are "contextual" keywords: they carry special meaning only in specific positions, and remain legal identifiers everywhere else, unlike true reserved keywords which are off-limits everywhere.
What counts as a keyword
A fixed, compiler-reserved word — class, if, while, private, void, and similar — that always means the same thing and can never be reused as a variable or class name.
What counts as an identifier
Any name you invent: variables, methods, classes, packages. It must start with a letter, underscore, or dollar sign, and contain only letters, digits, underscores, and dollar signs after that.
Case sensitivity
count, Count, and COUNT are three distinct identifiers to the compiler — capitalization is never ignored.
Contextual keywords
A small set of words like var, record, yield, and sealed act like keywords only in specific spots, and are still legal identifiers everywhere else — unlike true reserved keywords.
Convention versus rule
PascalCase for classes, camelCase for variables and methods, and SCREAMING_SNAKE_CASE for constants are strong community conventions that the compiler itself never actually enforces.
public class NamingDemo { static final int MAX_USERS = 100; public static void main(String[] args) { int userCount = 42; int UserCount = 7; System.out.println(userCount + " vs " + UserCount); System.out.println("Limit: " + MAX_USERS); }}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Java yourself — building beats watching.