Naming Convention

Naming Convention

Naming Convention

Naming Convention:

Java Naming Convention is a set of rules and guidelines for naming classes, variables, methods, and packages in Java programming language. Adhering to these conventions makes it easier for developers to read and understand each other’s code, and for tools to work with Java code.

Here are some of the commonly followed Java naming conventions:

  1. Package names: Package names are written in lowercase, and should be in reverse domain name format. For example, if your company’s domain name is “example.com”, then your package name should be something like “com.example.projectname”.
  2. Class names: Class names should be written in uppercase and should use camel case notation. For example, if you have a class that represents a car, its name should be “Car”.
  3. Interface names: Interface names should be written in uppercase and should use camel case notation. For example, if you have an interface that defines a set of methods for a vehicle, its name should be “Vehicle”.
  4. Method names: Method names should be written in lowercase and should use camel case notation. For example, if you have a method that sets the model of a car, its name should be “setModel”.
  5. Variable names: Variable names should be written in lowercase and should use camel case notation. For example, if you have a variable that represents the number of wheels on a car, its name should be “numWheels”.
  6. Constants: Constants should be written in uppercase and should use underscores to separate words. For example, if you have a constant that represents the speed of light, its name should be “SPEED_OF_LIGHT”.
  7. Packages and classes should have meaningful names that reflect their purpose and functionality.
  8. Use of abbreviations should be avoided, except for very commonly used ones like “max” for “maximum” or “avg” for “average”.
  9. Use of single-letter variable names should be avoided, except for loop variables.
  10. Avoid using reserved words as variable or class names.

These are some of the commonly followed Java naming conventions. Adhering to these conventions can help make your code more readable, understandable, and maintainable.

Join To Get Our Newsletter
Spread the love