Java Variable Naming Conventions.

Some basic convention rules for java variable:
1. Variable name always start with letter rather than number,$(dollar) and _(underscore).
Valid Variables Name Based On Convention:
int marks, int sumOfTwoNumbers, int listOfStudents etc
Variables Name Without Naming Convention:
int $marks, int _marks, int sum_Of_Two_Numbers, int list_of_students etc ( these all variables will work but i will suggest to not use these kind of variables and you must follow the proper naming convention for proper understanding of code and their meaning.
Invalid Variable:
int 1marks, int sum&Of, int list%Of etc
2. Name should be meaningful full word. If your variable name contains combination of two or more words then first word should be start with lower letter and then remaining words first letter should be start with capital.
3. If variables stores constant value then variable name should be in capital and if more then two words then separate words with underscore(_).
Example:
static final int RECORDS_PER_PAGE = 10;
static final int MAX_RECORDS_PER_PAGE=100;
4. Special characters are not allowed like #$%^&*@ etc
5. Variable are case-sensitive.

Leave a Reply

Your email address will not be published. Required fields are marked *