Name can be use to define class, method, variable and objects. following are Naming Rule & Conventions
Naming Rule & Conventions
Rules
- Name must contain alphabets, number or symbols ($ _)
- Name Must be start with either alphabets or symbol ($ _)
- Name Cannot be start with numbers.
- There is no limit of char to create name, but it should be meaningful.
- Name cannot contains any symbol except $ and _
Name | Valid/Invalid |
1StClass | Invalid |
ClassNo1 | Valid |
Employee_Details | Valid |
Person@Data | Invalid |
$Details | Valid |
_123_ | Valid |
$_ | Valid |
Batch112 | Valid |
Conventions
- Convention for Class Name
- It Must follow all the rule
- First Character of class name should be capital.
- If Class name is combination of more than one word then each word first char should be capital.
- Example :
Employee, PersonalDetails, EmployeeExperienceDetails
- Convention for Method name and Variable name
- It Must follow all the rule
- First char of name should be in small case.
- If name is a combination of multiple word then first char of each word should be in capital.
- Example :
print(), printDetails(), employeePersonalInfo()
- Convention for constants
- It Must follow all the rule
- Constant Name should in capital.
- 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)
- Example :
EMPLOYEE_INCREMENT, GRAVITY, PI
Keyword and Identifier in java
Identifier
- Is a custom/user define word use to create class name, method name, variable name or constant.
Keyword
- Are the reserve words by java.
- These words cannot be use for own purpose.
- 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