- 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.
- "Never do today what can be put off till tomorrow. " - Aaron Burr
- If a class proves difficult to code, put it off until you have a rest. You can then look at it with a fresh set of eyes
- Delegate the hard parts to code to another class
- Do not attempt to resolve all scenarios while coding, i.e., Wait to do locale specific encodings until after the initial code is complete.
- 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.
- Use local variables in loops. javac can assign an exact location of a local variable for a method at compile time.
- Avoid using Strings when you are modifying them. Strings are immutable. Therefore to "modify" a String, object creation and destruction must occur. Use StringBuilder and StringBuffer when Strings must be modified.
- Create Strings using the short form syntax to avoid creating additional objects.For example use: String s1 = "ABC";instead of: String s1 = new String("ABC");
- 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.
- Use StringBuilder instead of StringBuffer unless synchronization is required.
- 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.
- Use a HashMap instead of a TreeMap unless there is a requirement to maintain a sort order.
- Use a HashSet over a TreeSet unless there is a requirement to maintain a sort order.
- When using Vector, try to set the initial size to the expected maximum size to prevent having to grow the Vector. If you must grow a Vector use a reasonable value to increase the size.
- It is extremely important to try to appropriately size a HashTable to prevent reorganization.
When given a choice use local interfaces and local method calls on EJBs Shorten the distance between servers. Try to maintain dependent servers as close as possible. In clustered environments, try to keep remote communications on a separate private network interface. It is generally better to use a coarser stateless session bean to avoid JNDI lookups for fine grained operations. Avoid stateful session beans except as necessary. Set timers for non-activity on stateful session beans as low as possible to prevent "dead" connections waiting to timeout. Use Data Transfer Objects (DTO) to maintain granularity. DTOs must be Serializable.
- Reduce the number of network operations by returning complete results rather than smaller intermediate results.
- If database design constraints impose a specific database, use the advantages of the database where possible.
- If operations are performed on the database, consider using stored procedures and making JDBC calls.
- Do not use Entity Beans unless you must, use Java Persistence API (JPA) instead.
- Do not use Java Persistence API (JPA) unless you need it, or want to use some of its advanced capabilities.
- Limit the subset of data required to the minimum required for your program. Do not pull a whole row of data from table when you require only a few fields.