Sunday, 15 July 2012

Java Naming Conventions – Readability


Apart grammar, Java also includes a concept known as "conventions". Conventions increase the readability of the program. Conventions are applied to identifiers. An identifier, in Java, may denote a class name, a variable name or a method name. Java follows "Hungarian notation" in naming conventions. Conventions are very simple to remember.

1. Convention for class Names

The starting letter of each word, in a class name, should be of uppercase.

Identifier acceptsConvention says
myfirsthouseMyFirstHouse
firsthouseFirstHouse
houseHouse
wishesWishes
numberformatexceptionNumberFormatException

2. Convention for Variable Names

The starting letter of the first word should be of lowercase and the starting letter of all the remaining words should be of uppercase.


Identifier acceptsConvention says
myfirsthousemyFirstHouse
firsthousefirstHouse
househouse
wisheswishes
lightgraylightGray
priceprice
xx

3. Convention for Method Names

Convention for method is simply that of variable only but followed by parenthesis.


Identifier acceptsConvention says
myfirsthouse()myFirstHouse()
firsthouse()firstHouse()
house()house()
display()display()
indexof()indexOf()
lastindexof()lastIndexOf()





No comments:

Post a Comment

There was an error in this gadget