Subscribe Us

Naming Convention in Java

.
Java Naming Convention
The convention or the rule which you follow in order to name any thing in java such as class , method , variable , constant , package etc. are known as the java naming convention.

Camel case in java 
camel casing is a strategy to join multiple word and form a single word by following upper case letter and lower cases letter. In Java we uses Camel Case as a practice to declare the names of methods, variables, classes, packages and constants.
eg : studentId

Java Naming Convention - For Classes
  • Class name should starts with upper case Letter.
  • Every inner word should starts with upper cases letter.
  • Class name Should be noun eg. Button , Color etc.
  • There should no space in class name .
Example
eg : Employee , Student , String , StringBuffer .

public class Employee  

//business Logic  

}  

Java Naming Convention - For Interface
  • Interface name should starts with upper case Letter.
  • Every inner word should starts with upper cases letter.
  • Interface name Should be noun eg. Button , Color etc.
  • There should no space in Interface name .
Example 
eg : Serializable , RandomAccess .

interface Students  

//Business Logic 


Java Naming Convention - For Methods
  • Method Name should starts with lower cases letter .
  • Every inner word should starts with upper cases letter.
  • Methods should be a verb .
  • Method name should in mix case.
Example 
eg : speedUp () , post ().

public class Employee  


void classTeacher () 
//business Logic  

}  

Java Naming Convention - For Variable
  • Variable Name should starts with lower cases letter .
  • Every inner word should starts with upper cases letter.
  • Variable name Should not starts with "_" or "$" Sign .
Example 
eg : a , studentId , rollNum 
public class Employee  


int empId ;
//business Logic  

}  

Java Naming Convention - For Package 
  • package Name should starts with lower cases letter .
  • Every inner word should starts with lower cases letter.
  • Package name should accept the dot (.) to separate two words eg. java.lang

Example 
eg : java.io  , java.lang 

package com.javaacharya
public class Employee  
//business Logic  

}  

Java Naming Convention - For Constants 
  • All the word in constant name should be in upper case
  • use underscore (_) to separate 2 words.
Example 
eg : MAX_PRIORITY


public class Employee  


static final int MAX_AGE=20;
//business Logic  

}

Hope !!! The above lesson java naming convention helpful for You ...

Thank You !
Sandeep Yadav

Tags : Naming convention in java , java naming convention , Code convention in java , Coding convention in java , java coding convention  


Naming Convention in Java 

Post a comment

0 Comments