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".
What is the use of naming conventions in java?
A common culture among all Developers. Moreover, by seeing the name, you can guess the name belongs to a variable or class or method. See example,
MyFirstHouse : You can say it is a class name as each word starts with uppercase letter.
While doing a project in development, you must follow.
What is camel notation and pascal notation.
Java follows for class names camel notation and variables and method names, it is pascal notation
See more at:
http://www.dofactory.com/topic/1141/camelcase-pascalcase-vs-camelcase-pascalcase.aspx
class primitive
{
byte b=122;
int pricevalue=100;
public static void main(String args[])
{
primitive p=new primitive();
System.out.println(p.b);
System.out.println(p.pricevalue);
}
}
Sir in this code no error is coming while am using naming convention as “int pricevalue=100;” all are lower case letters what is the reason???
Java convention increases readability. If you do not want readability, do not follow simply. Remember, convention is not a rule. But readability is required as a developer.