View on GitHub

krishna-waidande.github.io

HOME

Rules for Indentation in a code

Variable Name

Eg :-

String name 		(It is valid attribute name for the class Company)
String companyname 	(It is invalid attribute name for the class Company)

Because since we are creating a class for Company it’s obvious that the name variable defined in the scope of the class company contains the name of the company.

Eg :-

int errorCode 				is valid. 
int errorcode,ErrorCode,Errorcode 	are invalid.

Class Name

Eg :- For class containing “Company detail” the class name should be

public class CompanyDetail {
/*
Class body
*/
}

Method Name

Eg :- For a method to create company.

void createCompany() { //valid name	
/* method body */
}	

void CreateCompany() { //invalid name	
/* method body */
}     

Proper Java Indentation

Import statements :

Like :

import com.krishagni.CRM.rest.Company;
import com.krishagni.CRM.rest.Factory;
import com.krishagni.CRM.rest.Dao.CompanyDao;

Unlike :

import com.krishagni.CRM.rest.Company;

import com.krishagni.CRM.rest.Factory;
import com.krishagni.CRM.rest.Dao.CompanyDao;

Curly braces :

Sample code showing proper curly brace usage

public String getName() {
return name;
}

Sample code showing improper curly brace usage

public String getName() 
{
   	 Return name;
}

Alignment :

Sample code with proper alignment

public class Company {
    CompanyDao dao;
    Company comp = new Company();    
    
    public Factory getAddcomp() {
	        return addcomp;
    }
}

There should be proper spacing before and after an operator.

Like : int name = 10;

Unlike: int name=10;

Remove unwanted Spaces :

Line Length :

XML, HTML Indentation

Like :

<bean id = "dao" class = "com.krishagni.CRM.rest.Dao.CompanyDaoImpl">
  <property name = "sessionFactory" ref = "sessionFactory"> </property>
</bean>

Unlike :

<bean id = "dao" class = "com.krishagni.CRM.rest.Dao.CompanyDaoImpl">
   	 <property name="sessionFactory" ref = "sessionFactory"></property>
</bean>

For Hbm file :

Something like this

<id name = "id" type = "int">
  <column name = "ID" />
</id>

Which helps us understand that id (java object property) is different from ID (Database column name)