Java Coding Tips And Tricks

Build and Deployment

Know the Difference Between Array and ArrayList

Interface is Better Than Abstract Class

Unit and Integration Testing

String Concatenation

  • Use the “+” operator: This is the easiest way to concatenate multiple strings, but it uses extra memory and reduces your program’s performance speed, especially when dealing with multiple strings in a loop. But this does not mean you should avoid this method totally. You can still use this to concatenate strings into a single statement.
  • The concat( ) method: This is a rarely used method. You have a better performance than when you use the ‘+’ operator; however, much slower.
  • Using StringBuffer: You have a much faster performance with this than when you use the two methods above. StringBuffer has been synchronized for multi-threaded operations, making this method thread-safe. This is not as fast as the StringBuilder due to the synchronous approach.
  • Append method of StringBuilder class: This is the same as the StringBuffer; however, the StringBuilder lacks synchronization for multi-threaded operations. If you are making a loop with multiple strings, then StringBuilder is the best choice.

Avoiding Memory Leaks by Simple Tricks

  • Ensure the database connections are often released after completing the query.
  • Try to utilize the Finally block always.
  • Instances in Static Tables must be released.
  • Store cases in static tables.

Encode in JSON

Better to Avoid BigDecimal and BigInteger

Optimize Your Code with Profilers

Float and Double

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store