
JLS Deep Dive: The Rules of the Language — Identifiers, Keywords, and the Underscore
Every language has its grammar, and Java's is defined by the Java Language Specification (JLS ). Before you can master the patterns, you must understand the vocabulary. This third chapter in our deep dive into Java SE 25 explores the fundamental rules that govern how we name things in Java. We'll look at the strict hierarchy of identifiers, reserved keywords, and the more flexible contextual keywords. In this article, you'll learn: The formal rules for creating a valid identifier (and why my-var is illegal but my$var is not). The difference between the 51 reserved keywords ( class , if , else ) and the 17 contextual keywords ( var , record , sealed ) that allow the language to evolve without breaking old code. The new role of the underscore ( _ ) as a reserved keyword for unnamed variables and patterns, a key feature for writing cleaner, more readable code. How the compiler resolves name conflicts through Shadowing and Obscuring . This is a guide to the foundational syntax of modern Ja
Continue reading on Dev.to
Opens in a new tab


