JAVA NAMING CONVENTIONS
Java naming convention is a standard pattern for writing your identifier name such as class, interfaces, methods, constants, variable, etc.
These patterns are not standard rules that you must have to follow, so it is known as the convention, not as rules. These conventions are approved and suggested by several JAVA communities such as Sun Microsystems and Netscape.
All the classes, interfaces, packages, fields, and constants are given according to the naming convention in Java. If you failed to follow these conventions in your code, then it may generate confusion or erroneous code.
Advantage of Java naming convention-
It increases the readability of the code. Readability is one of the important parts of the code, standard pattern makes your code is easy to read for yourself and also for others.
Important points for naming-
- The name of an identifier must not contain any white spaces.
- The identifier name should not start with any of special character like *(star), # (hash), $(dollar), & (ampersand) etc.
- Always choose a meaningful name for the identifier.
Types of cases-
Lowercase is a case notation where all the words are written in lower format.
identifier, character, etc.
In this case, all the words are written in capitalized format.
VARIABLE, CHARACTER, FIRST_DAY, etc.
In this case, each new word is starts with a capital letter.
CamelCase , CustomerDeposit, LordRama, etc.
In this case, the first word starts with a small character after that each new word start with a capital letter. It is the same as camel case notation except the first word.
displayRate, intrestEarned, deenDayalUpadhyaay, etc.
Java Naming Conventions-
A class name should be in CamelCase. As I told you before, try to use a meaningful name, so class name tries to take as any noun because the class deals with real-world object.
class Student, class Car, class CustomerAccount, etc.
A variable name should be in mixedCase because variables represent the value of something.
string studentName, int accountNumber, float salary, etc.
Constants name should be taken in UPPERCASE.
MAX_PRIORITY, DEFAULT_VALUE, MIN_HEIGHT etc.
A method name should be in mixedCase notation. Try to taker verb name because it may describe what the method does.
calculateSalary, displayValue, getAmount etc.
The package name should be taken in lowercase. Try to choose a short and meaningful name.
package awt, package newproject, package myclaculator etc.
An interface name should be in CamelCase notation. Its name should be like a class can do.
ActionListener, Runnable, IEnumerable.