• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What are utility methods ?

 
Shevesh Srivastava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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...

Shebu
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By utility methods do you mean utility classes ??

In that case, the java.io.Collections 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
 
Shevesh Srivastava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic