• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

Programming languages need a way to name elements — variables, methods, classes — while reserving certain words for the language’s own syntax. Without clear rules for what constitutes a valid name and what words are reserved, developers could write ambiguous or illegal code that confuses both the compiler and other programmers.

Core Idea

Identifiers are names given to program elements (classes, methods, variables). Keywords are predefined, reserved words in Java that cannot be used as identifiers. Java has strict naming rules: identifiers must start with a letter, underscore, or dollar sign, and can contain letters, digits, underscores, and dollar signs.

How It Works

During lexical analysis, the Java compiler tokenizes the source code. It distinguishes between keywords (like if, class, public) which trigger specific parsing rules, and identifiers (like myVariable, calculateTotal) which refer to user-defined entities. Keywords are always lowercase and have fixed meanings in the language specification.

Visual Explanation

java_identifiers Source Source Code Tokenization Lexer Java Lexer Source->Lexer Key Keywords if, else, class, public, static, void, return... Lexer->Key reserved words Ident Identifiers myVar, calculateSum, UserAccount, MAX_SIZE Lexer->Ident user names Other Literals & Operators Lexer->Other values, symbols

Semantic Network

semantic_java_ids THIS Identifiers & Keywords DT Data Types THIS--DT built from VAR Variables THIS--VAR builds into CTRL Control Flow THIS--CTRL builds into LEX Lexical Analysis THIS--LEX related

Key Properties

  • 67 keywords in Java 17 (including var, record, sealed, yield)
  • Case-sensitive: Class is an identifier, class is a keyword
  • Unicode support: Identifiers can use Unicode characters (e.g., π, 中国)
  • CamelCase convention: Classes use PascalCase, variables use camelCase, constants use UPPER_SNAKE_CASE

Connections

  • Built from: Java Data Types — identifiers are typed when declared
  • Builds into: Java Variables — variables are the primary use of identifiers
  • Builds into: Java Methods — method names follow identifier rules
  • Contrasts with: Java Operators — operators are symbols, not keywords/identifiers
  • Related: Java Control Flow — keywords like if, else, switch, case enable branching

Edge Cases & Gotchas

  • const and goto are reserved but unused — you cannot use them as identifiers, but they do nothing
  • true, false, null are literals, not keywords — but still cannot be used as identifiers
  • var is not a keyword — it is a “reserved type name” with special inference behavior
  • Dollar signs in identifiers are legal but strongly discouraged (used by compiler-generated code)