11 Jan 2016

Naming Conventions in java

1. Use full English descriptions for names. Avoid using abbreviations. For example, use names  like firstName,lastName, and middleInitial rather than the shorter versions fName, lName,  and mi.
2. Avoid overly long names (greater than 15 characters). For example, setTheLengthField should  be shortened tosetLength.
3. Avoid names that are very similar or differ only in case. For example, avoid using the names  product, products, and Products in the same program for fear of mixing them up.
For Ex : -
double tax1;       // sales tax rate (example of poor variable name)
double tax2;       // income tax rate (example of poor variable name)
double salesTaxRate;      //no comments required due to
double incomeTaxRate;     //self-documenting variable names
Variable Naming Conventions :-
Choose meaningful names that describe what the variable is being used for. Avoid generic names like number or temp whose purpose is unclear. Compose variable names using mixed case letters starting with a lower case letter. For example, use salesOrder rather than SalesOrder or sales_order.
Use plural names for arrays. For example, use testScores instead of testScore. Exception: for loop  counter variables are often named simply i, j, or k, and declared local to the for loop whenever possible.
for (int i = 0; i < MAX_TEMPERATURE; i++){
   boilingPoint = boilingPoint + 1;
}

Constant Naming Conventions :- 
Use ALL_UPPER_CASE for your named constants, separating words with the underscore character.  For example, use TAX_RATE rather than taxRate or TAXRATE. Avoid using magic numbers in the  code. Magic numbers are actual numbers like 27 that appear in the code that require the reader to figure out what 27 is being used for. Consider using named constants for any number other than 0 and 1. 

Method Naming Conventions :-
1.Compose method names using mixed case letters, beginning with a lower case letter and starting each subsequent word with an upper case letter. 

2.Begin method names with a strong action verb (for example, deposit). If the verb is not  descriptive enough by itself, include a noun (for example, addInterest). Add adjectives if necessary to clarify  the noun (for example, convertToEuroDollars). 

3.Use the prefixes get and set for getter and setter methods. Getter methods merely return the  value of a instance variable; setter methods change the value of a instance variable. For example, use the method names getBalance and setBalance to access or change the instance variable balance. 

4.If the method returns a boolean value, use is or has as the prefix for the method name. For  example, use isOverdrawn or hasCreditLeft for methods that return true or false values. Avoid the  use of the word not in the boolean method name, use the ! operator instead.For example, use  !isOverdrawn instead of isNotOverdrawn.

  

Parameter Naming Conventions :-
With formal parameter names, follow the same naming conventions as with variables, i.e. use mixed case, begin with a lower case letter, and begin each subsequent word with an upper-case letter. 

1.Consider using the prefix a or an with parameter names. This helps make the parameter distinguishable from local and instance variables. Occasionally, with very general purpose methods, the names chosen may be rather generic (for example, aNumber). However, most of the time the parameter names should succinctly describe the type of value being passed into the method. 
Example:- 
public void deposit(long anAccountNumber, double aDepositAmount)
  ... 
}
public boolean isNumberEven(int aValue)
  ... 
}

5 comments:

  1. Will do style work actually situation? Will need to individuals around secondary education always be ranked at if they go to elegance? http://ckgi62g14t.dip.jp https://imgur.com/a/4GZKI7o http://5o5m36mnq8.dip.jp https://imgur.com/a/pNOWRF3 http://w6n4ee1l37.dip.jp https://imgur.com/a/o143UO4 http://3d55r0t695.dip.jp

    ReplyDelete
  2. Thank you for another informative site. Where else could I get that type of information written in such a perfect way? I have a project that I'm just now working on, and I have been on the look out for such info. imac computer berlin

    ReplyDelete
  3. One of the knowledge stuffed blogs i've ever seen. It helps revamp existing technology and architecture, using constantly evolving strategies to drive improved market performance. reffer the given blog for more info Application Modernization Services or
    reach +18882075969 for more information

    ReplyDelete
  4. Really helpfull and easiest way to understand the concepts. Thanks for sharing please continue this wonderfull Work. If you want to know Anything about mendix Dont hesitate to Visit Mendix Certified developers | Mendix License or Reach out me @ +18882075969

    ReplyDelete
  5. Very usefull for the users also share blogs about Rapid Application Developmet Services if you need any suggestions please dont hesitate to call that number

    ReplyDelete