Java variable declaration best practices


Following are the best practices while declaring a variable.

1. Variables names should be short or long enough as per the scope. For example, loop counter variable, i is fine whereas employee as a loop variable.

2. Specific words should not be used as equals, compare, data.

3. Use meaningful names which can explain the purpose of the variable. For example cnt Vs counter.

4. Don't use _ to declare a variable name, Use camel casing. For example, employeeName is better than employee_name.

5. Each organization has its own syntax specific standards. Follow those rules to maintain consistency and readability.



raja
Published on 22-Jan-2018 05:38:59
Advertisements