Naming Convention in Java
Naming conventions make programs more understandable by making them easier to read.
Packages:
Package names are written in all lower case to avoid conflict with the names of classes or interfaces.
Companies use their reversed Internet domain name to begin their package names — for example, com.example.mypackage for a package named mypackage created by a programmer at example.com
Classes:
class names should be noun ,the first letter of every internal word should be capital and class name start with capital letter also. for example: — — — — class MyClass ,class Main etc.
Interfaces:
Interface names should be capitalized like class names.
Get Bushra Saifi’s stories in your inbox
Join Medium for free to get updates from this writer.
example: interface MyInterface , interface Person;
Methods:
Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.
Example: run(), runFast() .
Variables:
Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.
Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary “throwaway” variables. Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.
Example: int i; int noOfFloors;
Constants:
- Should be all uppercase with words separated by underscores (“_”).
Example: static final int MIN_WIDTH = 4;








