Naming Conventions in Java

This Core Java Tutorial “Naming Convention rules” post providing clear information about how to define variables, classes, methods based on programmer conventions.


 

Naming Conventions:
​​

  • Java supports convention rules.
  • It is mandatory to follow these rules while using pre-defined members of java library.
  • In case of user defined things, these rules are optional (but recommended).
  • Using convention rules easily we can analyze the program.
  • Convention rules play key role in Development of application by a group of developers.

 

Class convention rule :

  • Every word start with capital letter.
  • Also called “Camel Case” rule.
  • Spaces not allowed.

for example…
String
PrintStream
NullPointerException
FileNotFoundException
IndexOutOfBoundsException

 

Method convention rule :

  • Starts with lower case if it is a single word.
  • Every word starts with capital except first word, if method is a combination of words.
  • Spaces not allowed.
  • Also called “Mixed case”

for example….
main();
println();
nextFloat();
getAccountNumber();
getAccountHolderName();

 

Interface convention rule :

  • Every word start with capital letter.
  • Also called “Camel case” rule.
  • Spaces not allowed.

for example….
Runnable
ActionListener

 

Package naming convention :

  • Java Library is a collection of Packages.
  • Package can be represented with Single word.
  • Package must be in lower case.

for example…
java
javax
io
lang

 

Variable naming convention :

  • Should starts with lower case.
  • To identify easily, it follows method convention rule.
  • spaces not allowed.

for example….
balance ;
accountNumber ;
employeeID ;

 

Constant variable naming convention :

  • Recommended to be in UPPER case.
  • UPPER case just to identify a constant variable from ordinary variables.
  • Spaces not allowed

for example….
PI
MIN_PRIORITY
MIN_VALUE

Share this