Way2Java

Java Naming Conventions Readability

Java Naming Conventions Readability

Summary: Unlike C/C++, Java comes with naming conventions to increase the readability of code. This "Java Naming Conventions Readability" explains how to do it.

After knowing the rules of identifiers, it is the time to know the another grammar of Java 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 accepts Convention says
myfirsthouse MyFirstHouse
firsthouse FirstHouse
house House
wishes Wishes
numberformatexception NumberFormatException
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 accepts Convention says
myfirsthouse myFirstHouse
firsthouse firstHouse
house house
wishes wishes
lightgray lightGray
price price
x x
3. Convention for Method Names

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

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

Pass your suggestions to improve this tutorial "Java Naming Conventions Readability".