Chapter 2
A Discovery Tour: From API’s to Java Terminology

   2.1 Application Program Interfaces (API’s)
   2.2 Packages
   2.3 Classes
   2.4 Fields
   2.5 Methods
   2.6 Constructors
   2.7 Overloading
   2.8 Inheritance
   2.9 Organization of API’s
   2.10 Hierarchy of Classes
   2.11 Assignment #2: Java Terminology

2.1 Application Program Interfaces (API’s)

2.2 Packages

The root of the API specifications of the Java platform reveals that a library is made up of packages.

Java 2 Platform Packages
java.appletProvides the classes necessary to create an applet and the classes an applet uses to communicate with its applet context.
java.ioProvides for system input and output through data streams, serialization and the file system.
java.langProvides classes that are fundamental to the design of the Java programming language.
java.netProvides the classes for implementing networking applications.

2.3 Classes

The java.lang tells us that a package may deal with classes (of objects): concrete, interface, abstract, exception, and error.

Interface Summary
CloneableA class implements the Cloneable interface to indicate to the Object.clone() method that it is legal for that method to make a field-for-field copy of instances of that class.
ComparableThis interface imposes a total ordering on the objects of each class that implements it.
Class Summary
MathThe class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
ObjectClass Object is the root of the class hierarchy.
StringThe String class represents character strings.
SystemThe System class contains several useful class fields and methods.
Exception Summary
ArithmeticExceptionThrown when an exceptional arithmetic condition has occurred.
SecurityExceptionThrown by the security manager to indicate a security violation.
Error Summary
IllegalAccessErrorThrown if an application attempts to access or modify a field, or to call a method that it does not have access to.
OutOfMemoryErrorThrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.

2.4 Fields

The Math class indicates the inclusion of fields within classes.

Field Summary
static doubleE
The double value that is closer than any other to e, the base of the natural logarithms.
static doublePI
The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.

The above table lists the ‘E’ and ‘PI’ fields.

2.5 Methods

The Math class also indicates the inclusion of methods within classes.

Method Summary
static doublerandom()
Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
static doublesqrt(double a)
Returns the correctly rounded positive square root of a double value.

The above table shows the ‘random’ and ‘sqrt’ methods.

2.6 Constructors

The Object class indicates the inclusion of constructors within classes.

Constructor Summary
Object()

The above table exhibits a constructor named ‘Object’. (Note that the class is also named ‘Object’!)

2.7 Overloading

The String class indicates the possibility of having multiple methods and constructors of the same name. Such constructors and methods are said to be overloaded.

Constructor Summary
String()
Initializes a newly created String object so that it represents an empty character sequence.
String(byte[] bytes)
Construct a new String by converting the specified array of bytes using the platform’s default character encoding.
Method Summary
String substring(int beginIndex)
Returns a new string that is a substring of this string.
String substring(int beginIndex, int endIndex)
Returns a new string that is a substring of this string.

2.8 Inheritance

The Math class indicates the inclusion of the features defined in the Object class.

java.lang.Object 
  | 
  +--java.lang.Math 

2.9 Organization of API’s

                                    -- field 1
                                    |
                                    -- field 2
                                    |
                                    -- ...
                                    --
                                    |  constructor  1
                        --        --|-
                        |  class 1  |  constructor  2
                        |           |- ...
                        |           |
                        |           |- method  1
         --           --|           |
         | package   1  |           |- method  2
         |              |           -- ...
         |              |
         |              |- class 2
API  ’s --|              |
         |              -- ...
         |-
         | package   2
         --...
JavaTM 2 Platform 
     | 
     +-- java.applet 
     |       | 
     |       +-- Applet 
     |             | 
     |             +-- destroy() 
     |             +-- init() 
     +-- java.io 
     +-- java.lang 
     |       | 
     |       +-- Math 
     |       |     | 
     |       |     +-- PI 
     |       |     +-- random() 
     |       | 
     |       +-- String 
     |             | 
     |             +-- substring(int beginIndex) 
     |             +-- substring(int beginIndex, int endIndex) 
     +-- java.net 

2.10 Hierarchy of Classes

Logical organization reflecting on inheritance relationships-not on arbitrary packaging organization.

lang.Object 
  | 
  +--java.awt.Component 
  |     | 
  |     +--java.awt.Container 
  |           | 
  |           +--java.awt.Panel 
  |                 | 
  |                 +--java.applet.Applet 
  | 
  +--java.lang.Math 
  | 
  +--java.lang.String 

2.11 Assignment #2: Java Terminology

Due: Fr, Apr 4, at class

Answer the following questions for the Java 2 Platform, Standard Edition, v 1.4

  1. List at least five the packages whose names do not start with the character ‘j’
  2. Find a package that contains at most two classes
  3. Use the index to determine all the classes that contain a variable named ‘PI’.
  4. List all the classes containing a method named ‘println’.
  5. Identify a class that has two or more classes above it in the inheritance hierarchy.
  6. Identify a class that inherits features from no class
Q&A