Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

General method best_practices

577 views

Published on

This presentation discusses some general best practices which programmers should keep in mind when creating methods in Java.

Published in: Technology, Health & Medicine
  • Be the first to comment

  • Be the first to like this

General method best_practices

  1. 1. General Method Best Practices Parag Shah http://www.diycomputerscience.com
  2. 2. Follow Java coding conventions
  3. 3. The method name should be clear
  4. 4. Avoid using names of datatypes in methods Eg: getAccountsArrayList()
  5. 5. Names should be consistent Eg: Either delete() or remove()
  6. 6. Do not go overboard in providing convenience methods
  7. 7. Avoid long parameter lists
  8. 8. For parameter types, favor interfaces over classes
  9. 9. Use overloading judiciously
  10. 10. Do not invoke non final public or protected methods from the constructor of a non final class
  11. 11. Avoid returning null as far as possible. Throw Exception to signify a problem Return an empty list instead of null
  12. 12. A little something before leaving 5 == x instead of x == 5 “someStr”.equals(x) instead of x.equals(“someStr”)

×