How to use the Java API Documentation
Sometimes when you're just starting out programming and you just can't figure out how to make Java do exactly what you want it to, what you really need to do is check the Java API Documentation. You can search through all the classes and methods in the Java library, and I'm going to show you exactly how to do it.
Instructions
-
-
1
First head over to the latest version of the Java API Documentation at http://java.sun.com/j2se/1.5.0/docs/api/. This document holds every standard class in the java programming language. Remember, it's much better to check this for what you might need than to try to memorize all of it. There are literally thousands of classes, let alone methods, you'd have to memorize.
-
2
You may or may not know exactly what you need. Determine in general what you need your code to do and look through the API for something that sounds like it may be able to do what you want. For example, if you need the user to be able to click something in your GUI you might look for something like "button". You could scroll down until you came to "JButton" and you might want to check it out, sounds like it could be what you were looking for! This step could be long and grueling, but it's pretty much just how you have to learn it. Wish it were easier.
-
-
3
If you could find the class you needed in the last step, all you have to do is look through for the methods from it you might need. This page shows quite a few other helpful things like classes it extends (if a class is imported it also imports the methods of all classes it extends) and implements. For example, in the case above supplying the JButton class with a parameter "String text" could be nice to know if you want to label the button.
-
1
Tips & Warnings
Have patience, the more you learn the less you'll have to look up.
Don't be afraid to look stuff up, that's what it's there for.
Resources
- Photo Credit java.sun.com
Comments
-
C. K. Schicktanz
Feb 12, 2009
Thanks for the useful article!