Header Ads

  • Breaking Now

    What are some of the common mistakes Java developers, especially beginners make?

    Some of the most common mistakes that are committed by Java developers, especially who are newbies, are enumerated as given below:

    Not writing thread safe Java program

    A code is called a thread safe when a thread is modifying or reading shared data, no other thread can access it in a way that changes the data. So, when code depends upon a certain order of execution for correctness then other synchronization techniques are to be used.

    Poor exception handling

    While one throws top level exception object, it becomes difficult to trace to exact root cause of any problem in code, at every first instance. A good coder takes care of throwing explicit exception by proper handling of same.

    Poor indentation, formatting and documentation of code being done leading to poor maintainability

    A well indented code with proper documentation helps in better maintainability.

    Hard coding credentials

    A very commonly done mistake by beginners. The credentials must be handled in an independent manner from the code, viz. configuration files having them in encrypted format

    Failing to modularize code

    Do not make your code look like a procedural programming one. A better modularized code implementing Object Oriented programming concepts is the best way.

    Lack of code optimization practices

    It is understood for a newbie to be oblivious of code optimization techniques but being conscious of same from early days go a long way.  

    The most prominent example is when excessive garbage allocation is done. While creating many short-lived objects the garbage collector executes continuously, it degrades application performance. An example is of use of String objects which are immutable, each time a different String object is created for storing a new space in memory. The solution to deal it is to use mutable alternatives when instancing new objects.

    Proper allocation of heap size: Start with minimum heap size and gradually increase the size as the need multiplies. This 
    mechanism will keep a tab on speed of execution of code.

    Better concurrency control 
    techniques help in running multiple programs in parallel efficiently. It is advised to use optimistic locking with detached entities or an EXTENDEDPersistence Context.

    Post Top Ad

    Post Bottom Ad