Java – Naming Rules

Naming conventions:

  • It is recommended to follow Java Naming rules while naming classes, methods, variables, interfaces, constants etc.
  • Java Source code become more readable and understandable with naming rules.

Class: Every word in identity starts with capital letter. Spaces not allowed

String
PrintStream
NullPointerException
FileNotFoundException
ArrayIndexOutOfBoundsException

Method: First word starts with Lower Case and From Second word, every word starts with capital letters. No spaces allowed.

main( )
getName( )
getAccountHolderNumber( )

Variable: First word starts with Lower Case and From Second word, every word starts with capital letters. No spaces allowed

int  sum = 0 ;
float  shoeSize = 8.9 ;

Constant variable : All letters should be in upper case, words separate with underscore(_)

MIN_VALUE = 0;
MAX_PRIORITY = 10;

Package: package must represent with lower case letters.

java, lang, io, util, sql, http, servlet…

Abstract Class and Interface: Same as class

Runnable (interface)
InputStream (abstract class)
Scroll to Top