This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
My question: How should one search the SUN's API? Say, for example, I want to know if a method already exists in Java API. Then how should I search the Java API? How would I know which class and package that method more likely belongs to?
At the risk of engendering hatred aimed at yours truly...I find that sometimes I can actually intuit this sort of thing.
This sounds a LOT more pompous and arrogant than it really is...let me explain. First, you do need a good deal of experience with the basic package structure of the JDK and the most significant classes within those packages. This will not only give you the basic knowledge of the main APIs but a feel for how things are organized. (I admittedly also benefit from having followed the history of the development of these APIs, so I have quite a bit of knowledge that one could probably only attain by having worked with every JDK since 1.0...but I don't think this is that big a factor.)
Second, assume the JDK is perfect and all-encompassing.
Seriously. Assume it does everything you need it to do in the best, most elegant way you can think of, and puts that functionality in the place that makes the most sense to you based on what you know about the JDK packages and classes. Then go there, and expect it to be there. It often is. Sounds crazy, but Java's not that bad once you have the basics down. You will miss a lot at first, but the good thing about doing this is that you are actively engaging the APIs on an intellectual level, which means that your search through the APIs will be driven by logic, which means it will be connected to you at some unconscious, deep-seated emotional level because of the basic human need to be right. And quite often, when you miss, it will be not because the JDK is not perfect, but rather because it's in a more perfect place than you could think of. And when you do learn where it is, and it dawns on you why that's a more perfect place, your knowledge of the APIs is bolstered and you engage in what I believe is called a virtuous cycle.
As opposed to random, brute-force stabs at locating functionality using the function index...which is a vicious cycle of degenerating comprehension because it encourages a view of the APIs that is more library like in structure than OO-like.