As a general convention, should static method(s) be separated into another class from a class with instance methods?
Is there also an example of your reason?
There is no general convention that dictates that a static method must be separate from a non-static method. In fact, if the two methods are related enough to one another, it would be counter-intuitive to have the methods separated.
Recall what use case static methods (and fields) have: they're methods/fields that can be used without an instance of a particular class. This generally means that they hold valuable metadata or perform a useful operation that's related to their class instance, but would not require direct instantiation of that class.
Take, for example, Integer
. It has the static [final
] fields MAX_VALUE
and MIN_VALUE
. Since both of these fields contain fixed information that would not change between instantiations, it would not make sense to have to instantiate an Integer
to get this information.
Integer
also has the useful operation parseInt
, which takes a String
and turns it into an int
. We shouldn't require an instance of Integer
to convert from String
to int
, especially if we're not placing it into an instance of Integer
.
The overarching convention has been to keep related methods together, regardless of if they're static or not. You can see clearer examples of this in certain Java library classes, like Integer
.