Hi All!
I am new to Java and I referred regarding my question on the Net but not quite Satisfied. I want to know what the "Utility Class" in Java is?
Can anybody please tell me with an Example.
Thanks, david
Hi All!
I am new to Java and I referred regarding my question on the Net but not quite Satisfied. I want to know what the "Utility Class" in Java is?
Can anybody please tell me with an Example.
Thanks, david
It's usually a class which only has static methods (possibly with a private constructor and marked abstract to prevent instantiation). It only exists to make other classes easier to use - for example, providing a bunch of static methods to work with String
values, performing extra actions which String
itself doesn't support.
Utility classes generally don't operate on classes you have control over, as otherwise you'd usually put the behaviour directly within that class. They're not terribly neat in OO terms, but can still be jolly useful.
To extends Jon Skeet's answer, java.lang.Math
, java.util.Collections
and java.util.Arrays
are typical examples for such classes.