WHAT'S NEW?

Camel Casing Rule (Major area where beginners make mistake)

Camel Casing Rule is a convention which has to be followed , Remember even java library follows it.
Rule states that:


"Whenever a class name,method name or a variable name is combination of two or more words and if the combination is found to be adjacent in the dictionary , then the first letter of second word is used in Lower CASE"

The statement is a little tricky to understand, let see it other way round.

"Whenever a class name, method name or variable name is a combination of two or more words and if the combination is not available in dictionary first letter of second word is used in UPPER CASE."

For example, consider two classes

Uniform and DriverManager.
Uni and form are two different words but it is also found as a single word in dictionary, hence f in form is in Lower Case, whereas Driver and Manager are two different words bit there combination is not found in the dictionary, hence M of manager is written in Upper Case.


Convention for class name.


First letter of a class should be used in UpperCase.


Hence class names will be

  • UniformResourceLocator
  • ResultSet
  • ActionEvent

Convention for method and variables.


First letter of a method or a variable should be in Lower Case.

Hence method names are like

  • setText()
  • openCap()
  • setToolTipText()
  • getIcon()

Why to use conventions

Conventions are the best way to make sure a uniform pattern is followed while coding.
Consider a scenario,
You are the project head for a project where detail of empoyee are managed.
Camel Casing Rule-javawithz.in
Tom,Alex and Mike are your three developers' Tom and Alex follow the conventions while Mike doesn't . Tom and Alex manage basic details of Employee while Mike was handling salary details.
Now Tom and Alex make methods like setName(),getDepartment()..while method and class designed by Mike will look like Employeesalary...here S of Salary should be in upper CASE but it is not  and method designed  will like  getsalary()
Hence if the classes designed by all three of them are combined then it would create a problem for those who follow conventions, for example Tom will fire a method getSalary(), it is not available because of silly conventions, Hence quite a big mistake to get firing from your Boss...



0 comments:

Post a Comment