Next page | Contents page |

The standard API and its documentation

The most useful standard packages

All of these (and many many more) are available in the JDK you installed in Exercise 1.

java.lang - language basics; no need to import explicitly

java.util - common utility classes, useful data structures

java.io - files, input/output

java.text - text formatting (eg, for dates, numbers)

java.net - network access: URLs, sockets, HTTP, etc

java.awt & javax.swing - graphics, GUI and events - all covered later

See the API documentation for details of each package. How to do this is coming next.

Later we will explain how to create your own packages and put classes in them.

Navigating the documentation

On java.sun.com you can both access all of the documentation online and also download a copy to keep on your own hard disc. I like to have a downloaded copy but for now we will use the online one. Follow the steps below.

  1. Point your browser at http://java.sun.com/javase/6/docs/ (this link will open a new window).
  2. The coloured diagram gives you access to many useful documents but for the moment go past it and click in the link just below it: "Java SE 6 API Documentation".
  3. You now see a page divided into 3 scrollable windows. In the top left window is a list of packages. Scroll down that to find the package called java.lang and click on it.
  4. The second window on the left should have changed from listing all classes to listing just those that are in java.lang. Actually the list is in several parts, headed Interfaces, Classes, Enums, Exceptions and Errors. So far we have only met classes, so we will focus on that part of the list. Scroll down to Integer and click on that.
  5. The right hand window, the biggest of the three, now shows the documentation of class java.lang.Integer. It begins with some general description and then tabulates summaries of the (non-private) fields, constructors and methods in the class. Scroll down to the Method Summary table and find parseInt (). It shows you that the definition of this method is static int parseInt (String s), with a single sentence summarising what it does. (You can also see that there is another overloaded version of parseInt with a second parameter.) Often that is all you need to know but click on the name parseInt to see what happens.
  6. You jump further down the page to get a more detailed description of what parseInt does. Notice that there are lots of links throughout the declaration. So if you want to find out more about String, you can very easily jump to the documentation for that.
  7. Do now try some of the links and explore the documentation.

The really useful thing is that all Java APIs are documented in the same way, by using the javadoc utility program supplied in the JDK. Later in the course you will see how easy it is to generate similar documentation for your own code. I guarantee you will be wowed by that!

My own API documentation is available here: http://www.grelf.net/docs. Explore it and see how similar it is to Sun's documentation. You will soon be able to do this too.

Questions you could investigate as practice in using the API documentation

1. What is strange about the month field of class Date?

2. Why do we need the class GregorianCalendar?

3. Which package is class ArrayList in, and why is it useful?

4. What is particularly useful (for commercial software) about BigDecimal?

5. Where is the value of pi?

6. What is class Long for?

7. Which classes have NaN fields, and what does NaN mean?

8. What is the maximum value a double variable can have?

9. How can you generate random numbers? Why might you?

Next page | Contents page |