Java Coding Convention and Rules to Declare the Name convention


Java Naming conventions



Java Naming Convention For Classes
  • Class name start with upper case letter and every inner word starts with upper case letter.
  • This convention is also known as camel case convention.
  • The class name should be nouns.

Example:- The example of java naming convention for classes are  listed below

String , StringBuffer ,InputStreamReader ……etc

public class Emp
//Business Logic
}  

Java Naming Convention For Interface

  • Interfaces starts with upper case and every inner word starts with upper case letter.

Example:The example of java naming convention for Interfaces are listed below 

Serializable Cloneable RandomAccess…etc


interface Printable 
//Business Logic

}  
Java Naming Convention For Enum

  • Enum starts with upper case letter and every inner word are starts with capital letter.
Example : 
Enum, ElementType, RetentionPolicy…etc

Java Naming Convention For Annotation

  • Annotation starts with upper case letter and every inner word are starts with capital letter.
Example :
Override, FunctionalInterface …etc

Java Naming Convention For Method

  •  Method name starts with lower case letter and every inner word starts with upper case letter.
  •  This convention is also known as mixed case convention
  • Method name should be verbs.
Example:-
 post() charAt() toUpperCase()


class Employee 
//method 
void draw() 
//Business Logic

}  

Java Naming Convention For Variable

  • Variables start with lower case letter and every inner word starts with upper case letter.
Example :-
 out in pageContext …etc


class Employee 
//variable 
int id; 
//Business Logic

}  

Java Naming Convention For Packages

  • Package Package name is always must written in lower case letters.
Example :- 
java.lang java.util java.io …etc


  package com.javatpoint; //package 
class Employee 
//Business Logic

}

Java Naming Convention For Keywords

  • Keywords While declaring keywords every character should be lower case.
Example: 
try,if,break,continue…..etc

Java Naming Convention For Constants

  • Constants:-While declaring constants all the words are uppercase letters .
Example: MAX_PRIORITY MIN_PRIORITY NORM_PRIORITY


class Employee 
//constant 
 static final int MIN_AGE = 18; 
//Business Logic

}  

NOTE:- The coding standards are mandatory for predefined library & optional for user defined library
but as a java developer it is recommended to fallow the coding standards for user defined library also.





Post a Comment

0 Comments