Java Coding Best Practices

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....

Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  Java Coding Best Practices ?


Coding conventions (Best Practices) are a set of guidelines for a specific programming language
that recommend programming style, practices and methods for each aspect of a
piece program written in that language. These conventions usually cover file
organization, indentation, comments, declarations, naming conventions, programming
practices, programming principles, programming rules of thumb, etc. Software programmers
are highly recommended to follow these guidelines to help improve the readability of
their source code and make software maintenance easier.

Some of the Best Practices for Java development are as follows.
• A class should not have more 2000 lines or so.
• Line Size should be fixed, usually that could be either 80 or 120 chars.
• Every Class and method should have the JavaDoc comments to give an idea on
    the purpose of that method or class.
• Method name should be started with a lower case alphabet.
• Use "StingBuffer ()" instead of concatenating the Strings like "xyz+abc".
• Use "String literals" like "abc" instead of using new String("abc").
• Avoid using System.gc() or Runtime.gc().
• Should not have any System.out statements in your code.
• Should not have any exception.PrintStackTrace () statements in your code.
• Should not catch the Runtime Exceptions like "NullPointers".
• Make sure the Exceptions will be propagated to Invoker class without dropping them
    in the middle.
• Use ArrayList instead of Vector , in the same way use HashMap instead of HashTable.
• Try to create the Collections such as ArrayList, HashMap with proper initial Size to
    avoid unnecessary delaying in Object creation.
• Avoid using Static in MultiThreaded Env.
• Avoid having Static methods in your Business logic layer,  if not you may lose the
    advantages of OOPs such as inheritance, runtime polymorphism.
• You need to use either Synchronized or Read/Write locks for your business methods
    in Multi Threaded ENV.
Close all external Connections such as Database-Connections, IO-Stream Connections
     in finally block.
• Check if you have any additional "For loops" or unnecessary Object Creation.
• Use Prepared Statements.
• Use Batch processing for Bulk Updates.
Clone (Prototype pattern) the Objects instead of creating New objects by using
    "new" operator.
• Use Object Pooling instead of creating unlimited new Objects.
• "SetTimeouts" for the DB Transactions as well as external Web Service or RMI calls.
• Use "ASYNC process" if you are performing a task that would not impact the User such
    as sending emails or running some Time-Consuming Reports.
• Use "Lazy Loading" while loading the Object Graph (which has Child Parent relation)
    into memory.
• Use Singleton classes or Caching APIs for storing the Static Data.
• Follow the Layered Structures, do not propagate the Web-Layer Objects like HTTPRequests,
    HTTPSessions ect., in Business-Logic-layer.
• Use the DTOs or VOs for Data Transfer between the Layers.

Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

Java Coding Best Practices

Java Coding Best Practices


Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free