Static methods are necessary in Java for a variety or reasons including:
For example, the Integer class includes a static method
public String toString(int value);that converts a primitive int value to its printable String form. Since int values are not objects, this operation cannot be formulated in object-oriented style.
Similarly, an operation
public String squeezeWhiteSpace(String s);that returns a String identical to s with all spaces and tabs removed must be expressed as a static method because the library String class cannot be modified or extended.
Finally, all operations on arrays must be expressed in static (procedural) form because array types do not have conventional class definitions; they are built-in to the Java virtual machine. We will discuss arrays in Chapter 2 when we address imperative programming in Java.