Java Reference
In-Depth Information
1.1.2. Methods must be in a class, even if you don't need or want one
Some time ago, Steve Yegge wrote a very influential blog post called “Execution in the
Kingdom of the Nouns.” [ 2 ] In it he described a world where nouns rule and verbs are
second-class citizens. It's an entertaining post and I recommend reading it.
2 Read the post from March 30, 2006 at Steve Yegge's blog: http://mng.bz/E4MB .
Java is firmly rooted in that world. In Java all methods (verbs) must reside inside classes
(nouns). You can't have a method by itself. It has to be in a class somewhere. Most of the
time that's not a big issue, but consider, for example, sorting strings.
Unlike Groovy, Java does not have native support for collections. Although collections
have been a part of Java from the beginning in the form of arrays and the original
java.util.Vector and java.util.Hashtable classes, a formal collections
framework was added to the Java 2 Standard Edition, version 1.2. In addition to giving
Java a small but useful set of fundamental data structures, such as lists, sets, and maps, the
framework also introduced iterators that separated the way you moved through a collection
from its underlying implementation. Finally, the framework introduced a set of polymorph-
ic algorithms that work on the collections.
With all that in place we can assemble a collection of strings and sort them as shown in
the following listing. First a collection of strings must be instantiated, then populated, and
finally sorted.
 
Search WWH ::




Custom Search