Sunday, 22 January 2017

NAMING CONVENTIONS IN JAVA

1. Naming a class, interface, enum

  • Class name should be "noun", because it represents things.
  • Class name should be in title case which means every word's first letter should be capital letter.
  • For example : Bank, Customer, Animal, StringWordsFinder, PrintStream.
2. Naming Variable
  • Variable name also should be a "noun" because it represents values.
  • In variable name, "first word first letter should be small and after that every word's first letter should be capital"
  • For example : customerName, username, password, balance, minimumBalance.
  • In final variable all the letters should be capital and words must be connected with "_". For example : MIN-BALANCE, PI, RED, BLUE etc
3. Naming Methods
  • Method name should be a "verb", because it represents action.
  • In method name, "first word first letter should be small and after that every word first letter should be capital and should follow () ".
  • For example : getUsername(), getPassword(), getBalance().
4. Naming Package
  • All letters should be small, and its length should be as short as possible.
  • For exanple : io, lang, util, dao, beans, blogic etc


No comments:

Post a Comment