I was a bit curious as to which Java classes I used most often so I figured I count them. Instead of counting each individual use I decided that I'd just count the number of times a class was imported. Here's the command line:

$ find . -name "*.java" | xargs cat | grep "^import java" |\
 sort | uniq -c | sort -nr | head -20
I ran this on the 100,000 lines or so of code that make up Sphinx-4 with the following results:
    122 import java.io.IOException;
    108 import java.util.List;
    101 import java.util.Iterator;
     62 import java.util.Map;
     50 import java.util.HashMap;
     50 import java.net.URL;
     48 import java.util.ArrayList;
     42 import java.util.logging.Logger;
     41 import java.io.File;
     37 import java.util.LinkedList;
     33 import java.util.Set;
     28 import java.util.HashSet;
     26 import java.io.InputStream;
     23 import java.util.Collections;
     22 import java.util.logging.Level;
     22 import java.io.BufferedReader;
     21 import java.util.Properties;
     21 import java.io.Serializable;
     20 import java.util.StringTokenizer;
     20 import java.util.Collection;

I was surpised to see IOException on top of the list, but the rest confirmed what I expected, that the Collections api dominates. The Collections API is my friend.

Comments:

Wouldn't this scheme of finding usages skip the java.lang classes? A related thought that I had, was a special JDK javadoc page that would bubble the more often used classes & packages to the top, making them easier to find.

Posted by Sumit on September 11, 2004 at 01:49 PM EDT #

The result is not referable, because it skips such imports : java.util.*.

Posted by Siamak on September 21, 2004 at 06:42 AM EDT #

Post a Comment:
Comments are closed for this entry.

This blog copyright 2010 by plamere