Page 187 - Introduction to Programming with Java: A Problem Solving Approach
P. 187

                5.2 The API Library
When working on a programming problem, you should normally check to see if there are pre-built classes that meet your program’s needs. If there are such pre-built classes, then use those classes—don’t “reinvent the wheel.” For example, user input is a rather complicated task. Java’s Scanner class handles user input. Whenever you need user input in a program, use the Scanner class rather than writing and using your own input class.
There are two primary advantages of using pre-built classes. Using pre-built classes can save you time since you don’t have to write the classes yourself. Using pre-built classes can also improve the quality of your programs since the classes have been thoroughly tested, debugged, and scrutinized for efficiency.
Searching API Class Library Documentation
Java’s pre-built classes are stored in the Application Programming Interface (API) class library, which is more simply known as the API library. You should be able to find documentation for the API library at Sun’s Java API Web site:
http://java.sun.com/javase/6/docs/api/
The API library contains tens of thousands of pre-built methods defined in thousands of classes. The classes are organized in almost two hundred groups called packages (a pack- age is a group of classes). It’s unlikely that you’ll be able to memorize the names of all those
5.2 The API Library 153
       Use available resources.
  methods, where they are, and what they do. So how do you locate the particular piece of pre-built software
Apago PDF Enhancer
that might be just what you need for your current programming project?
Use a textbook (like this textbook☺) to get you started with selected sample classes and methods. Then
go to Sun’s Java API Web site and browse. See Figure 5.1. It shows that the Web site’s window is partitioned
package list
class list
      When Overview is selected, the right pane displays a package list and package descriptions.
     Figure 5.1 Sun’s Java API Web site

















































































   185   186   187   188   189