Wednesday 26 October 2016

Code conventions in java

It is a good habit to adhere to the set of rules that can make your and peers life during and after programming in java comfortable. Remember the below given points while declaring these in your java code : 

1)Classes & interfaces : The first letter should be capitalized. If several words are linked together to form the class name then the first letter of the inner word should be capitalized. This format is known as camelCase.

Example
class Employee {}, or 
class EmployeePensionCalculator{}

Same rule goes for Interfaces as well. 
Example
interface Runnable{}, or
interface RandomAccess{}


2)Methods : The first letter should be lowercase, and then normal camelCase rules should be used. In addition, the names should typically be verb-noun pairs.
Example 
getLocation,
doCalculation,
setCustomerName,


3)Variables : Like methods, the camelCase format should be used, starting with a lowercase letter. Sun recommends short, meaningful names, which sounds good to us.
Example :
buttonWidth,
accountBalance,
myString


4)Constants : Java constants are created by marking variables static and final. They should be named using uppercase letters with underscore characters as separators.
Example :
MAX_SALARY,
MIN_AGE

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If you are looking for a reference book on java then we recommend you to go for → Java The Complete Reference
Click on the image link below to get it now.