Skip to content
This repository was archived by the owner on Apr 27, 2024. It is now read-only.

Code Convention

Khiem Ton That edited this page Feb 1, 2024 · 1 revision

Database:

  • Use snake_case for naming. Example: user_id.

Naming Classes:

  • Use PascalCase.
  • Avoid using abbreviations that are not clear.
  • Do not use prefixes when naming classes:
    • Incorrect: IUser, RepoUser
    • Correct: User, UserServiceImpl, UserRepository

Naming Interfaces:

  • Use PascalCase.
  • Example: UserService.java.

Naming Methods:

  • Use camelCase for naming methods. Example: classifyStudent.
  • Method names should clearly reflect their functionality. Example: calculateAverageScore.
  • Avoid vague or unclear names. Example:
    • Incorrect: display, calculate
    • Correct: showDetails, computeTotal
  • Do not differentiate method names with numbers. Example: calculateScore1, calculateScore2

Naming Variables:

  • Use camelCase for naming variables. Example: int averageScore, String fullName.
  • Do not use prefixes. Example:
    • Correct: String address
    • Incorrect: String strAddress
  • Variable names should be mnemonic, avoid unclear abbreviations. Example:
    • Correct: String address
    • Incorrect: String addr
  • Do not name variables with just one letter like x, y, z, except for counter variables like i, j, k.
  • Avoid overly long or short variable names as they can make the program confusing or the meaning of the variable vague.

Importing Libraries:

  • Only import necessary libraries. Do not use import-all.
  • Example: Use import java.util.List; instead of import java.util.*;.

Clone this wiki locally