๐ŸŽ‰ Special Offer !    Code: GET300OFF    Flat โ‚น300 OFF on every Java Course
Grab Deal ๐Ÿš€

Java Naming Conventions  


Java Naming Conventions:
  • Naming convention refers to a set of standardized rules and guidelines for naming classes, methods, variables, and other identifiers to ensure code readability and maintainability.
  • Below table shows an example of naming convention in java :
    Naming Single Word Two Words Three Words
    Classes, Interfaces Example MyExample MyExampleDemo
    Methods example() myExample() myExampleDemo()
    Variables example my_example my_example_demo
    Constants EXAMPLE MY_EXAMPLE MY_EXAMPLE_DEMO
    Packages example my.example my.example.demo
  • Key Notes for Each Category:
    1. Classes and Interfaces:
      • Use PascalCase (capitalize the first letter of each word).
      • Example: MyClass, UserAccount.
    2. Methods:
      • Use camelCase (first word lowercase, subsequent words capitalized).
      • Always name methods as actions or verbs.
      • Example: getDetails(), calculateTotal().
    3. Variables:
      • Use camelCase for instance variables and local variables.
      • Separate words with an underscore (_) only when necessary.
      • Example: user_age, total_price.
    4. Constants:
      • Use UPPER_SNAKE_CASE (all uppercase, words separated by underscores).
      • Example: MAX_VALUE, DEFAULT_TIMEOUT.
    5. Packages:
      • Use lowercase letters with dots separating levels of hierarchy.
      • Reflect the project's domain or structure.
      • Example: com.example.project.