M/F 2:30-3:20   
in G01 Gates Hall

CS 1130: Transition to OO Programming

Spring 2016

Part 7. Specifications, Testing, and Debugging

Module 1, Part 8

API Packages

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.

We will only cover a few of them in this part. Here are the API specs for Java 1.6 if you wish to learn more.


Contents

1. Using API Specs on the Web

Web Lecture

Reading: Lecture Notes
Gries/Gries, Appendix II.1, p. 493–496.

Comments: 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

Web Lecture

Reading: Lecture Notes (Lecture Slides)
Gries/Gries, Sec. 5.5.1, pp. 172–174.

Comments: 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

Reading: Lecture Notes

Comments: Each primitive type has a corresponding wrapper class. The html page of lecture notes is only a summary. For details, look at the API specs on the web or the ProgramLive CD, page 5-1.


4. Autoboxing

Web Lecture

Reading: Lecture Notes (Sample Code)

Comments: 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

Web Lecture

Reading: Lecture Notes (Lecture Slides)
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

Comments: An instance contains a list of objects, and one can add elements to the list, delete them, and retrieve them.


6. Constraining ArrayLists

Web Lecture

Reading: Lecture Notes (Lecture Slides)
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

Comments: This brief web lecture 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.