Helper and Utility Classes in Java

In an object oriented programming model we can define a helper class as a way to provide some functionality that aren’t the main goal of the application or class in which they are used. A helper class can have instance variables and multiple instances as well. A utility class is a special case of helper class where all methods are static.

Usually Utility and Helper Class are used to do basic functions help so that developers don’t have to implement it multiple time. A general rule could be:

  • Utility Class: static class that can be easily accessed and imported everywhere. In order to prevent instantiation of a Utility class a common practice is to make the class final and create a private constructor.
  • Helper Class: class helping another class. Can have multiple instances and instances variables.

One thing to notice is that using a class in a Static way means no class instantiation and use of Stack memory instead of Heap Memory. This will bring a slightly less overhead because of compile time binding.

Leave a Reply

Your email address will not be published.

*