views:

90

answers:

3

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

+2  A: 

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.

Jon Skeet
A: 

There's a utility package, java.util, that contains a bunch of stuff like dates, times, string tokenizers... Not sure if that's what you're talking about.

Sancho
+1  A: 

To extends Jon Skeet's answer, java.lang.Math, java.util.Collections and java.util.Arrays are typical examples for such classes.

Landei