Naming Rule & Conventions

Name can be use to define class, method, variable and objects. following are Naming Rule & Conventions

Naming Rule & Conventions

Rules

  1. Name must contain alphabets, number or symbols ($ _)
  2. Name Must be start with either alphabets or symbol ($ _)
  3. Name Cannot be start with numbers.
  4. There is no limit of char to create name, but it should be meaningful.
  5. Name cannot contains any symbol except $ and _

 

NameValid/Invalid
1StClassInvalid
ClassNo1Valid
Employee_DetailsValid
Person@DataInvalid
$DetailsValid
_123_Valid
$_Valid
Batch112Valid

 

Conventions

  1. Convention for Class Name
    1. It Must follow all the rule
    2. First Character of class name should be capital.
    3. If Class name is combination of more than one word then each word first char should be capital.
    4. Example :

Employee, PersonalDetails, EmployeeExperienceDetails

 

  1. Convention for Method name and Variable name
    1. It Must follow all the rule
    2. First char of name should be in small case.
    3. If name is a combination of multiple word then first char of each word should be in capital.
    4. Example :

print(), printDetails(), employeePersonalInfo()

 

  1. Convention for constants
    1. It Must follow all the rule
    2. Constant Name should in capital.
    3. If it is combination of multiple word then you should use _ in between the words (this is also known as Snaky way of creating name)
    4. Example :

EMPLOYEE_INCREMENT, GRAVITY, PI

 

Keyword and Identifier in java

  1. Identifier

    1. Is a custom/user define word use to create class name, method name, variable name or constant.
  2. Keyword

    1. Are the reserve words by java.
    2. These words cannot be use for own purpose.
    3. Examples: class, int, byte, short, long, public, static, final, private, protected, if, for, else, do, while etc.

 

 

 

Join WhatsApp : Click Here

 

Join Telegram : Click Here

 

All Full Stack Java Study Material