Menu
Coddy logo textTech

Naming Conventions

Part of the Fundamentals section of Coddy's Java journey — lesson 11 of 73.

In Java, it's important to follow naming conventions to keep your code readable and maintainable. Here are some key rules:

  • Variable Names:
    • Use camelCase: Start with a lowercase letter, then capitalize the first letter of each subsequent word (e.g., firstName, studentCount).
    • Choose descriptive names that indicate the variable's purpose (e.g., userAge instead of ua).
    • Avoid single-letter names except for simple loop counters.
  • Constant Names:
    • Use UPPER_SNAKE_CASE: Write in uppercase letters, with words separated by underscores (e.g., MAX_VALUE, PI_VALUE).
    • Use for values that don't change throughout the program.
  • General Rules:
    • Names can contain letters, digits, underscores, and dollar signs.
    • Names must start with a letter, an underscore _, or a dollar sign $.
  • General Rules:
    • Names are case-sensitive (myVariable is different from myvariable).
    • Avoid using Java's reserved keywords (like int, class, public, etc.).

Following these conventions helps make your code more understandable, especially when working in teams or revisiting your code later.

Cheat sheet

Java naming conventions help keep code readable and maintainable:

Variable Names:

  • Use camelCase: Start with lowercase, capitalize first letter of subsequent words
  • Choose descriptive names: firstName, studentCount, userAge
  • Avoid single-letter names except for loop counters

Constant Names:

  • Use UPPER_SNAKE_CASE: MAX_VALUE, PI_VALUE
  • For values that don't change throughout the program

General Rules:

  • Names can contain letters, digits, underscores, and dollar signs
  • Must start with a letter, underscore _, or dollar sign $
  • Names are case-sensitive
  • Avoid Java reserved keywords

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals