Header Ads

  • Breaking Now

    Java Coding Standards : Layout

    In professional Java programming world, it is essential that your developed code should follow some coding standards as per guidelines set by your organization or your client is technical enough to send you those details. A question arises why do I need such a practice, answer is very simple. To make life easy for those who are going to maintain or enhance your code. A better documented, neat-clean code with all programming standards and guidelines followed does not only enhance maintainability but also performance and robustness of your code. You may find these details to start with at Sun's website.The coding conventions set by Sun for Java recommends that others should ideally follow and no harm in transforming it to suit your organizational or clients' needs . It covers filenames, file organization, indentation, comments, declarations, statements, white space, naming conventions, programming practices and includes a code example.

    The purpose of programming standards is to support the development of consistent and well-written applications. It helps developers to create a code base with a uniform presentation, which is understandable, reusable and maintainable. It also helps developers to avoid common pitfalls of Java that leads to robust, reliable and portable code.
    In series of articles I will touch upon various aspects of Java coding standards,best practices and guidelines.

    While writing Java classes it is quite important how you layout your code.It means how you structure and order constituents of your Java code.The order in which package,import statements and file header are placed:

    - The first line of code represents 'package declaration'.
    <blank line>
    - The import list in sorted order
    <blank line>
    - The file header

    It is important to have specific import statements rather with suffix '*'.Hence no "*"  in import statements.You must separate Sun classes and project specific classes.The order in which the parts of a class or interface declaration should appear in the java files is as below:

    a. Class/interface documentation comment (/**...*/)
    b. Class or interface statements
    c. Class/interface implementation
               comment (/*...*/), if necessary
    {This comment should contain any class-wide or interface-wide information  that wasn't appropriate for the class/interface documentation comment.}
    d.Variables should always be defined before constructors and methods, irrespective of the order of variable declarations.

    In next post, I will discuss about how we should document our code so that Javadoc utility will help build the documentation from code.

    Post Top Ad

    Post Bottom Ad