Best Practice Java
Best Practice Java
com/pulse/30-best-practices-java-programming-robert-mitchell/
/30-best-practices-java-programming
=>If a parameter is passed into a method then perform the necessary checks on
it as soon as possible. The earlier you check it, the less likely errors
and exceptions are to occur. This includes checking if objects are null,
empty, false, the correct type, etc .
5. Prefer Enums to Strings When Dealing With a Known Number of Possible Values:
=>An example of a utility method would be a method that accepts two integers and
returns the larger integer of the two
=Excessive usage can hurt performance as objects are converted from a primitive
type
to the corresponding wrapper type or vice versa. This can also lead to Null
Pointer Exceptions if you aren�t careful
=>L'autoboxing permet de transformer automatiquement une variable de type
primitif en un objet du type du wrapper correspondant
14. Values Used Commonly Throughout the Code Base Should Be Defined In a Constants
File:
16. Use Method Names and Field Names That Are Descriptive:
=>Using .equals() will check to see if they contain the same value. Using == will
check to see if they are the same object.
19. When Doing a Null Comparison, Put the Word �null� on the Right Side of the ==
Operator:
20. Use Blank Lines to Separate Code Into Logical and Readable Blocks:
22. When Possible, Reuse Existing Classes Rather Than Reinventing a Solution:
25. In A POJO, Use Private Fields With Setters & Getters Rather Than Allowing
Direct Access to Fields:
26. Think About JUnit Tests While You Are Writing Your Code:
29. When Creating an Interface, Be Careful Not to Include More Abstract Methods
Than Necessary:
30. When You Refactor Code, Communicate the Changes to Other Potential Users of
That Code:
----------
code smells ou mauvaises odeurs sont des mauvaises pratiques de conception
logicielle qui conduisent � l�apparition de d�fauts.