This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Remember, going for the "All Classes" in the JavaDoc will reveal Enums and Interfaces. If we strictly only want classes, this will not suffice. I'd say we'd have to go one step further and inspect the JavaDoc of each entry in the "All Classes" link and see if the resource in question is a class, enum or interface. Sounds like the job of a PERL script if you ask me.
This has actually made me wonder how many classes there are. Oh, I hope this silliness doesn't get me in trouble with the admins. Perhaps this should go into 'meaningless drivel.'
My count for the number of classes in the Java 5 JDK is 3280. However, I think that includes interfaces, enums, inner classes and all sorts of other junk.
>>Look through it for the class keyword, preceded and followed by whitespace (not .class)
But what if the word 'class' is used in a comment of an interface? You'd need to parse out all comments from the Java files as well, especially comments that come before the class declaration. Or are we parsing just compiled class files and not source files?
The 'one-upmanship' on this thread is getting difficult to bear.
Indeed, the point was to do it programatically, not just answer the question.
Joined: Nov 07, 2008
Rofl, I just realized who you were Cameron. I really enjoyed your SCJA book
Joined: Oct 13, 2005
No oneupmanship intended. You could restrict your search to one instance of the word "class" per file, but that would miss private classes.
Reading class files in combination with reflection (Enum.class.isAssignableFrom(cls), cls.isInterface) looks like the only way to make sure you get all classes and filter out all enums and interfaces. That still leaves anonymous classes, but the naming pattern ($xxx with xxx being some number) can help you with that.