Naming Conventions


  • A naming convention is a rule to follow as you decide what to name your identifiers (e.g. class, package, variable, method, etc..).
  • Different Java programmers can have different styles and approaches to the way they program. By using standard Java naming conventions they make their code easier to read for themselves and for other programmers.




Cases in Java Naming Convention:

Using the right letter case is the key to following a naming convention:

  • Lowercase is where all the letters in a word are written without any capitalization (e.g., while, if, mypackage).
  • Uppercase is where all the letters in a word are written in capitals. When there are more than two words in the name use underscores to separate them (e.g., MAX_HOURS, FIRST_DAY_OF_WEEK).
  • CamelCase (also known as Upper CamelCase) is where each new word begins with a capital letter (e.g., CamelCase, CustomerAccount, PlayingCard).
  • Mixed case (also known as Lower CamelCase) is the same as CamelCase except the first letter of the name is in lowercase (e.g., hasChildren, customerFirstName, customerLastName).
Examples:

Classes:

class MyClass
{

}

Objects/Variables:

String myName;
MyClass myObject;
Scanner scannerObject = new Scanner(System.in);

Methods:

void myMethod()
{
}
String myName = scannerObject.nextLine();

Constant Variables:

static final char END_OF_FILE = 'e';
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Popular posts from this blog

if..else..if Loader

Nested if..else Statement