Most Java classes are about object orientation, but they are occasionally used
just for organizing a bunch of frogs... erhm, methods, in a box.
java.lang.Ma
th is one such class, it does not get used to make instances. Everything in
it is "static" (for the static fields, this means there is one shared instance
of them that can be accessed directly from the class, without need for
instances, and for the static methods, it means they are invoked directly on the
class, without any instance object). Notice that java.lang.Math has no useful
constructor, and that every single method declaration starts with
"static".
For comparison, you could see the java.lang.StringBuilder class, which is a "normal" class that you are meant
to make instances of: it has four public constructors, and none of its public
methods are static.
Basically in C++, the things in java.lang.Math would all
be static global variables and free-standing global functions, and
java.lang.Math itself would either be a namespace, or just be left out entirely.
Actually, most languages including Python have some way to clean way to write
free-standing functions. But for some sort of 'language purity' reason, Java
forces all variables and 'functions' (methods) to be members of a class. Steve Yegge famously complained about this six years ago. Having worked on
some large Java projects around then, I can testify that the 'noun-ification' of
large Java systems really does produce the kind of horrible code he shows
towards the end of the post. =) [ Reply to This | Parent | # ]
|