Lesson 3
Keywords
A focused lesson on Java reserved words, identifiers and naming rules.
Java Track
Save progress as you learn.
61 lessons
Lesson content
Keywords are the reserved words in Java that have a predefined meaning. They form an important part of Java syntax and cannot be used as names for variables, classes, or methods.
What makes a keyword special
- Keywords are predefined and reserved by the language.
- Each keyword has a special meaning in Java.
- Keywords are always written in lowercase.
- Keywords cannot be used as identifiers.
Examples of Java keywords
- class
- while
- for
- interface
- abstract
Rules for identifiers
Identifiers are the names you assign to variables, constants, functions, classes and arrays. They must follow Java naming rules and must not match reserved keywords.
- The first character must be a letter, underscore, or dollar sign.
- Identifiers cannot start with digits, but they may contain digits later.
- Whitespace cannot be included.
- Identifiers are case sensitive.
Valid and invalid examples
- Valid: PhoneNumber, PRICE, radius, a, a1
- Invalid: 1sum, Sum 1