Java Naming Conventions Readability

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".

6 thoughts on “Java Naming Conventions Readability

    1. S. Nageswara Rao, Corporate Trainer

      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.

  1. p.pavan

    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???

Leave a Reply

Your email address will not be published. Required fields are marked *