Wednesday, July 13, 2016

Coding Standards and Naming conventions

Coding Standards and Naming Conversion

Why Coding Standards?

  • A program is written once , but read many times

    • During debugging
    • When adding to the program
    • When updating the program
    • When trying to understand the program
  • Anything that makes a program readable and understandable saves lots of time , even in the shot run.

Naming Conventions

  • Naming a class

    • Class name should be in title case , means Every word first letter should be capital letter.
    • This is also known as UpperCamelCase.
    • Choose descriptive and simple names.
    • Try to avoid acronyms and abbreviations.
    • Naming Class Example

      package com.javasunderesan
      public JavaNamingVariableDemo{
      }
  • Naming a Variable

    • Variable name should be start with small letter.
    • Use lowerCamelCase.
    • Example: name, mobileNumber, age.
    • For final variable all its letters should be capital and words must be connected with "_".
    • Example: MAX_COUNT, MIN_COUNT.
    • Naming Variable Example

      package com.javasunderesan
      public JavaNamingVariableDemo{
      String firstName;
      String lastName;
      int mobileNumber;
      final static int MIN_WORDS=300;
      }
  • Naming a Method

    • Method name should be verb because it represents action.
    • Use lowerCamelCase for naming methods
    • Example: setFirstName(), getFirstName(), getLastName().
    • Naming Variable Example

      package com.javasunderesan
      public JavaNamingMethodDemo{
      String firstName;
      String lastName;
      int mobileNumber;
      final static int MIN_WORDS=300;
      public void getFirstName()
      {
      return firstName;
      }
      public void setFirstName(String firstName)
      {
      this.firstName = firstName;
      }
      }
  • Naming a Package

    • All letters should be small.
    • like in java io, util, applet
    • Example: com.javasunderesan
    • Naming Variable Example

      package com.javasunderesan
      public JavaNamingMethodDemo{
      }

No comments :

Post a Comment