I would like to share with you some tips to deal/prevent NPE in your code: The BIG IMPORTANT rule: do NOT assign / pass / return null value and keep your code as cohesive as possible. Programming tips / techniques: 1. Return an empty collections instead of null. For example: List: Set: Map: 2. Return … Continue reading Avoid NullPointerException in Java
Tag: Programming
Why extends is evil
Improve your code by replacing concrete base classes with interfaces The extends keyword is evil; maybe not at the Charles Manson level, but bad enough that it should be shunned whenever possible. The Gang of Four Design Patterns book discusses at length replacing implementation inheritance (extends) with interface inheritance (implements). Good designers write most of their code in terms … Continue reading Why extends is evil
10 Most Useful Java Best Practice Quotes for Java Developers
Quote 1: Avoid creating unnecessary objects and always prefer to do Lazy Initialization Object creation in Java is one of the most expensive operation in terms of memory utilization and performance impact. It is thus advisable to create or initialize an object only when it is required in the code. Quote 2: Never make an … Continue reading 10 Most Useful Java Best Practice Quotes for Java Developers
Encapsulation in java and its relation with abstraction
Most of you will agree that encapsulation and abstraction together brings a lot of confusion. Most blogs add only confusion further. Lets solve this puzzle. I started working on this post after my previous post “Understanding abstraction in Java“. My goal was to understand encapsulation in java and how it relates to abstraction. As soon … Continue reading Encapsulation in java and its relation with abstraction