What’s in a name: Java naming conventions

  • In the base package name, put your company’s domain in reverse order & then add the project name & maybe version - all in lower case.
  • Use nouns, written in CamelCase (with first letter capital), for class names. Class names should say what function or variable to expect from it as well.
  • Choose short, meaningful nouns for variables and fields, saying what values or variables they hold, in camelCase.
  • Avoid single character variables. Avoid underscore & dollar as first letters. For boolean values, start with ‘is’ or ‘has’, since they are yes/no questions.
  • Put constants in all-caps, with underscores to separate words.
  • Make methods and functions verbs, implying what they do in 2-3 words in camelCase. Use ‘get’ & ‘set’ to start the names of data fetching and setting functions.
  • Use similar conventions as classes and interfaces for enums and annotations, respectively, with enums in all-caps.

Full post here, 5 mins read