Skip to content
C

Keywords and Identifiers

Keywords are reserved words that already have a special meaning in Java, such as class, public, static, and if. Identifiers are the names you create yourself for things like classes, variables, and methods, such as Student or totalMarks.


1. What are Keywords and Identifiers?

Keywords are reserved words that already have a special meaning in Java, such as class, public, static, and if. Identifiers are the names you create yourself for things like classes, variables, and methods, such as Student or totalMarks.

2. Why is it used?

Keywords tell the Java compiler what action or structure you intend (like defining a class or writing a loop), so they cannot be reused as names for your own variables. Identifiers, on the other hand, let you label and organize your own code meaningfully.

3. Real-Life Example

Think of keywords like traffic signs — "STOP," "YIELD" — which have a fixed meaning everyone must follow and cannot be renamed. Identifiers are like the names you give your own pet or your own notebook — completely up to you, as long as you follow basic naming rules.

4. Syntax

java
// Keywords (cannot be used as variable names) class, public, static, void, int, if, else, for, while // Identifiers (names you create) int studentAge; String courseName;

5. Example Program

java
public class IdentifierDemo { public static void main(String[] args) { int studentMarks = 85; // studentMarks is an identifier System.out.println("Marks: " + studentMarks); } }

Output:

Marks: 85

6. Key Points to Remember

  • Keywords are fixed and reserved; you cannot use them as identifier names.
  • Identifiers must start with a letter, _, or $, and cannot start with a digit.
  • Java identifiers are case-sensitive, so total and Total are different names.

Mock Test

  • Keywords and Identifiers - Quick Test

    10 questions on reserved words and the rules for names you create.

    10 questions · 10 min · Easy
    Start Mock Test

Coding Problems