Naming conventions make programs more understandable by making them easier to read. They can also give information about the function of the identifier for example whether it’s a constant, package, or class which can be helpful in understanding the code.
Naming Convention is not forced to follow that why it’s known as the convention, not a rule. But it’s a good habit to follow the naming convention it’s will make the code more sensible and easy to understand for the other developers who are working on the same project or supposed to modify any code change in the existing project.
Rules for Naming in Java
Packages – The prefix of a unique package name is always written in all-lowercase. It should start from the domain name like com, ed, gov, mil, net, org etc. and subsequent components of the package name vary according to an organization’s own internal naming conventions. Such conventions might specify that certain directory name components by division, department, project or machine names.
Examples — com.sun.eng , com.apple.quicktime.v2, edu.cmu.cs.bovik.cheese …etc
Classes – Class names should be nouns, very the first letter should be capital. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations.
Examples — class Raster; , class ImageSprite;
Interfaces – It should be adjective and names should be capitalized like class names.
Examples — interface RasterDelegate; interface Storing;
Methods – Methods should be verbs, the first letter should be lowercase, with the first letter of each internal word capitalized.
Examples — run(); runFast(); getBackground();
Variables – Variables name should start with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.
Examples — int i; char c; float myWidth;
Constants – The names of variables declared class constants and constants should be all uppercase with words separated by underscores (“_”).
Examples — static final int MIN_WIDTH = 4;
static final int MAX_WIDTH = 999;
static final int GET_THE_CPU = 1;
Selenium Video Tutorial: