Naming-Conventions-in-Java .

In this session i have discussed naming conventions in Java .


Naming Conventions

Naming conventions is used to write the name of class , interface , package , variable , method etc . It is a conventions not a rule . But if you do not follow it will create confusions Java uses the CamelCase for writing the name of class , interface , method , variable , package etc .

The CamelCase uses compound or mixed phrases such as each word begin with capital letter or first word with lower case letter and rest of all will capital .


Some naming conventions in java as follows

Class

It should be start with capital letter . In mix case all the first letter of internal word should be capitalized .

It should be noun like Color , Button etc .

Always use whole word and avoid acronyms and abbreviations .

Example :

    class Employee{
       
       //code snippet
    }
    
    class HondaByke{
        
        //code snippet
    }
    

Interface

It should be start with capital letter . In mix case all the first letter of internal word should be capitalized .

Always use whole word and avoid acronyms and abbreviations .

It should be adjective like runnable , ActionListener .

Example :

    interface Sports{
       
       //code snippet
    }
    

Method

It should be start with lower letter . In mix case all the first letter of internal word should be capitalize .

Always use whole word and avoid acronyms and abbreviations .

It should be verb like main .

Example :

    class Employee{
       
       void salary(){
       
         //code snippet
       }
    }
    

Package

It should be start with lower case letter . In mix case all the first letter of internal word should be capitalize .

If package contains multiple words , It should be seperated with dot(.) .

It is always top level domain name like org , edu etc .

Example :

    package com.org //package
    

Variable

Variable name should be short and meaningfull .

It is follow all the identifier rules .

Example :

    int empid;
    string emp_name;
    

Constant Variable

It should be uppercase and word seperated with underscore(_) .

It is follow all the identifier rules .

Example :

    static final int MAX_WIDTH=100;
    


Welcome to AndroidATPoint.

back image                     next image