Reading and Understanding Java's API Documentation: Appendix
Reading and Understanding Java's API Documentation: Appendix
Reading and Understanding Java's API Documentation: Appendix
When you download the documentation, you get several directories. In the top-level directory is a file named index.html (or index.htm). Open this file in your Web browser. 3. Click the API & Language link, which is near the top of the front page, as shown in Figure A-1. This takes you farther down on the same Web page.
4. Click the Java 2 Platform API Specification link, as shown in Figure A-2. The browser transports you to the start of the API pages, which are shown in Figure A-3.
5. Click the Index link at the top of the page to open the index, as shown in Figure A-4. A list of letters is near the top of the index. Click the P link to go to the section with println in it.
6. In the P section, do a search for println to find the println entries. Most Web browsers enable you to search for something like println in the text of a page. Heres how:
A. Make sure the browser knows that you want to search in the big frame that takes up most of the page (and not in the smaller frames on the left side of the page). To do this, click your mouse inside the big frame. (Dont click a link. Click on some neutral white area of the frame.) B. Open the browsers Find dialog box. On most browsers, pressing Ctrl+F coaxes the Find dialog box out of hiding. C. When you see the Find dialog box, type println in the text box and click the boxs Find or Find Next button. 7. Pick one of the println entries. The P section has a big boatload of println entries, as shown in Figure A-5. The entries differ from one another in two ways: * Each entry says println(int), println(String) , or println( someOtherTypeName ). The type name can differ from one entry to another. * Each entry says that println is a method in class java.someStuff.someMoreStuff. The class can differ from one entry to another.
At this point, it pays to poke around. If youre trying to print something like "Hello world!" , you want one of the println(String) entries. On the other hand, if youre trying to print the value of amountInAccount, youll probably choose a println(double) entry. Now, suppose youve decided on println(String). You can choose from three println(String) entries. One says its a method in class java.io.PrintStream, the next is a method in class java.io.PrintWriter, and the third is a method in class java.sql.DriverManager. Which of these three entries do you choose? Well, what youre really trying to call is something named System.out.println . If you go through the whole lookup rigmarole with System.out, youll find that System.out has type PrintStream. (See Figure A-6.) So the entry you decide to choose is println(String) - Method in class java.io.PrintStream.
8. Click the link for the entry that youve chosen. When you click the println(String) link, the browser takes you to a page that explains a println method, as shown in Figure A-7. The page tells you what println does (Print a String and then. . . .) and points to other useful pages, like the page with the documentation for String.
Clicking the System link makes your browser display the documentation page for the System class, as shown in Figure A-9.
3. On the documentation page for the System class, find the out variable. If you use your Web browsers Find dialog box, you have to click the Find Next button several times. (The word out is so common, it appears several times in several different contexts on the System documentation page.) When youve found what youre looking for, you see a table like the one shown in Figure A-6. 4. In the tables out row, click the PrintStream link. According to the documentation, the out variable refers to an object of type PrintStream . This means that println is part of the PrintStream class. Thats why youre clicking the PrintStream link. 5. On the documentation page for PrintStream, find println(String). You see an explanation like the one shown in Figure A-7.
To create the API documentation, the folks from Sun Microsystems ran a program called javadoc. The javadoc program took lines like these right out of the PrintStream.java file and used the lines to make the documentation that you see in your Web browser. Other Java programmers -- people who dont work for Sun Microsystems -- do the same thing. In fact, everyone who writes Java code uses the javadoc program to generate documentation. So everyones Java documentation looks like everyone elses Java documentation. When you know how read to the standard API documentation, you know how to read anybodys homegrown Java docs. And yes, you can use the javadoc program too. When you download the JDK (see Chapter 2 for the details), you get the javadoc program as part of the deal. To find out more about turning your program comments into Web pages, visit this books Web site.