How to increase Java performance.

  • Always use the simplest classes possible to get the Job Done.
  • Never code your own frameworks unless the performance is lacking. Reuse code and frameworks.
  • Use open source frameworks which are established and tested.
  • Learn Collections and use them correctly. Use "lightweight" collections and avoid "heavyweight" collections where synchronization is not required.
  • Use constants where possible by using static final in the variable declaration.
  • Use Enum instead of integer constants. Enums are more flexible and are typesafe.
  • Avoid casting and using instanceof
  • Use synchronized methods instead of code blocks.
  • Avoid synchronized calls within a synchronized method or code block.
  • Do not recalculate constants inside a loop.
  • "Fast Fail" - If a method fails, or throws an exception have it exit the loop quickly. Break loops early.
  • Never use String or StringBuffer for parsing characters. Use a character array.
  • Try to set the StringBuilder or StringBuffer to the size required, or maximum size required during initialization to prevent a performance penalty while resizing.
  • Avoid using StringTokenizer if there is a performance requirement. Use a more specific (custom) tokenizer to split Strings. StringTokenizer is a generic utility that is synchronized internally.
  • Avoid using generic object collections. Use generics with collections to avoid having to cast objects.
  • Use a LinkedList over an ArrayList if there a large number of insertions and deletions.
  • When given a choice use local interfaces and local method calls on EJBs.


Source: http://www.hostitwise.com/java/java-perfromance-tips.html


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email