File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes What are utility methods ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What are utility methods ?" Watch "What are utility methods ?" New topic

What are utility methods ?

Shevesh Srivastava

Joined: Jan 19, 2010
Posts: 3

Can anyone explain me what are utility methods, why are they called so and whats the difference between them and other *should I call* methods. And yes while writing this query I also remember from collections framework that there are also some methods that we call Algorithms and to some methods we simple call them methods.. so what the difference between them ?

Thanks in advance...

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
By utility methods do you mean utility classes ??

In that case, the class for instance is a utility class.

These classes contain methods that you could easily create yourself, there is not much logic behind them, but they come in handy and you need to use them quite often so the designers decided to include them in the Java API

JDBCSupport - An easy to use, light-weight JDBC framework -
Shevesh Srivastava

Joined: Jan 19, 2010
Posts: 3
for example, mkdir and mkdirs in FIle class are called utility classes.
second, methods like that for binarysearch and all are called algorithms and methods like add(object) is not.
Craig Taylor
Ranch Hand

Joined: Jul 17, 2008
Posts: 64
The mkdir() and mkdirs() are not essential for the usage of the core object's operation (reading, opening, writing etc... ) ..

My definition : Functions or classes are are not esstential or critical to the parent class but add useful or often used code.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20273

I regard mkdir() as an essential (or maybe a better word: "primitive") method. Without it, how would you create a folder? In other words, for me a utility method is a method that cannot be expressed using other (public) methods.

mkdirs() on the other hand can be implemented using (for instance) getParentFile() and mkdir() so that is indeed a utility method.

How To Ask Questions How To Answer Questions
subject: What are utility methods ?
It's not a secret anymore!