Skip to main content

more options

Part 7. Specs, testing, and debugging

Module 1, part 8. API classes

Introduction

Java comes with over 300 predefined packages, called API (Application Programmer Interface) packages. Some of the classes in the packages, like class String (in package java.lang) are essentially built in to the language. Others provide classes and methods for reading and writing files, dealing with URLs (addresses of pages on the world wide web, for example), and constructing GUIs (Graphical User Interfaces). As you use Java more and more, you will get familiar with the API that comes with Java and rely on it more and more.

Here are the API specs for Java 1.6.

Contents

No. Topic Discussion
1. Using API specs on the web.
(blecture doc)
Reading: Gries/Gries, Appendix II.1, p. 493–496.
We browse the API specs on the web, showing you what they look like and how to find what you want.
2. Wrapper class Integer.
(blecture doc ppt.pdf)
Reading: Gries/Gries, Sec. 5.5.1, pp. 172–174.
Primitive type int has a corresponding wrapper class, Integer. Each instance of Integer "wraps", or contains, an int value. Class Integer (1) allows us to treat an int value as an object and (2) provides a place to put constants and functions that deal with int values.
3. Wrapper classes for other primitive types. (html) Each primitive type has a corresponding wrapper class. The html page is only a summary. For details, look at the API specs on the web or the ProgramLive CD, page 5-1.
4. Autoboxing.
(blecture doc java)
Autoboxing, which was introduced to Java in version 5, provides for automatic conversion between each primitive type and its wrapper class. Autoboxing is not discussed in the current edition of Gries/Gries.
5. Class ArrayList.
(blecture doc ppt.pdf)
An instance contains a list of objects, and one can add elements to the list, delete them, and retrieve them.
6. Constraining ArrayLists.
(blecture doc ppt.pdf)
This brief blecture shows how to constrain elements of a list to have a certain class, thus reducing the chance of making errors by adding the wrong objects to the list.
  Reading for items 5 and 6: Gries/Gries, Sec. 5.3, pp. 184–189, covers an older class Vector, instead of ArrayList. The concepts are the same, but the methods will be slightly different.