APPENDIX a the Java API Packages
Total Page:16
File Type:pdf, Size:1020Kb
APPENDIX A The Java API Packages The JDK provides many packages (JDK 1.1 had 26 packages) and others are being developed (such as the 2D, 3D and Media packages). You must prefIx the names of the packages in Table A.I with "java.". TABLE A.1 The Java API packages PackaKe name Contents applet Applet related classes awt Platform-independent windowing classes awt.datatransfer Support for cut and paste style operations awt.event DeleKation event model classes awt.image Image manipulation classes awt.peer Native windowing facilities classes beans Beans facilities for developers io Input and output classes lang Basic Java classes lang. reflect Java reflection classes math BigDecimal and BigInteger classes net Java networking facilities rmi Remote method invocation classes rmi.dgc Distributed garbage collection rmi.registry Facilities for mapping names to remote objects rmi.server Facilities for the server side of RMI security Java Security for signed applets security.acl Access control list security. interfaces Digital Signature Algorithm interface specifIcations sql JDBC SQL interface classes text Internationalization facilities 428 Java and Object Orientation util General utili classes util.zip Java Archive (JAR) su ort classes For further information on these packages, see books such as Chan and Lee (1996) and Gosling and Yellin (1996). APPENDIXB The java.lang Package B.l INTRODUCTION The java. lang package contains the classes and interfaces which are the basis of the Java environment (as distinct from the Java language). For example, the class Obj ect (the root of all classes) is defined in this package. This package is automatically imported into every Java program (whether it is an application or an applet). The facilities provided by this package are, therefore, always available. Notice that the errors and exceptions generated directly by the Java Virtual Machine are defined in this package. Figure B.1 shows the classes and interfaces defined in this package and the relationships between them. A solid line indicates inheritance; a dashed line indicates an implementation; a rectangle indicates a class; and an oval indicates an interface. B.2 THE CLASSES The Obj ect class is the root of the class hierarchy. Every class has Obj ect as a superclass. All objects, including arrays, implement the methods of this class. Boolean The wrapper for the primitive type boolean. It provides methods for working with boolean values and converting boolean values to strings and vice versa. 429 430 Java and Object Orientation Byte final Serializable java.io Double final Float final Integer final Object Long final Short ( Cloneable final ( Runnable Error ThreadDeath Exception FIG. B.1 The java.lang package Character The wrapper for char values. It provides methods for manipulating and converting chars (e.g. from uppercase to lowercase). Class Instances represent classes and interfaces in a running Java application. Objects are constructed automatically by the Java Virtual Machine and by calls to the defineClass method in the class loader. ClassLoader An abstract class, of which subclasses extend the manner in which the Java Virtual Machine dynamically loads AppendixB 431 Compiler Support and related services for Java-to-native-code compilers. Math Many standard mathematical operations such as tan, cos, etc. To promote portability, the algorithms that implement the mathematical operations must match the output of algorithms available from the network library (netlib) package "Freely Distributable Math Library". Number An abstract class, which is the superclass of Byte, Double, Float, Integer, Long, and Short. Subclasses must provide methods to convert the represented numeric value to byte, double, float, int, long, and short. Byte The wrapper class for byte values. Double The wrapper class for double values. Float The wrapper class for float values. Integer The wrapper class for int values. Long The wrapper class for long values. Short The wrapper class for short values. Process Allows native operating system programs to be run via the exec command (or one of its variants). Run time Environment and system related functions such as garbage collection, tracing and library loading. Securi tyManager An abstract class that allows applications to implement their own security policy. String Character strings which cannot be changed. StringBuffer Sequences of characters which can be altered. The primary methods used with this class are insert and append. System A variety of utility methods such as standard input, standard output, and error output streams; access to externally defined properties; a way of loading fIles, libraries and interfaces to the Run time class. Thread Lightweight processes, called threads. A java program can have multiple, potentially interacting, threads. 432 Java and Object Orientation ThreadGroup An instance represents a group of threads that can be treated as a single entity. Throwable The root of all error or exception classes. Error Indicator of a serious problem in a program (programs are not expected to catch errors). ThreadDeath Although a subclass of Error, it is not really an error condition; it is generated when a thread terminates. You should only need to catch an instance of ThreadDeath if the program performs housekeeping (or similar) activities when a thread terminates. Exception The root class of all exception classes in Java. void An uninstantiable placeholder that references the primitive Java type void. B.3 THE INTERFACES Serializable Defines the common protocol for objects which can be saved to a file (defined in the java.io package, but implemented by many classes in this package). Cloneable Indicates that the implementing object can be cloned (i.e. you can copy this object field by field). Runnable Defines the common protocol for objects which expect to be run in their own thread. APPENDIXC The java.util Package C.l INTRODUCTION This package provides a variety of utility classes such as Date and Random, as well as the Vector and HashTable growable data structures. SeriaIizabIe ).. ..' • .,. ( java.lang ~:. >... ~,;;;,;.;.;.;;~ - - .... ' . .. ' ~:;;=;:~~ ( Enumeration ) ( EvenU.lstener ) TooManyUstenetlException ( OblefVef ) RuntimeException java.1ang FIG.C.l The java.util package 433 434 Java and Object Orientation C.2 THE CLASSES BitSet A growable index of bits (boolean values) which provides logical operators such as or and xor, as well as operations to set and reset bits in the set. Calendar Provides conversion functions between date objects and integer fields representing dates. Subclasses interpret a date according to the rules of a specific calendar system, for example GregorianCalendar. Date Represents a particular date and time. Dictionary An abstract superclass of classes which associate a key with a value (see Hashtable). EventObj ect The root for all event objects (for example, AWTEvnt). GregorianCalendar Implements the Gregorian calendar, with AD and BC dates. Hashtable Implements a traditional hashtable. Locale Represents a region (geographical, political or cultural). ResourceBundle Contains locale-specific objects which programs can load. The program code can be largely independent of the user's locale; most, if not all, of the locale-specific information is in the resource bundles. ListResourceBundle An abstract subclass of ResourceBundle which handles resources in a list oriented manner. PropertyResourceBundle An abstract subclass of ResourceBundle which handles resources using a set of static strings from a property fIle. Observable An abstract superclass of classes that can have observers associated with them and respond to the setChanged and notifyObservers methods. Properties Instances represent system (and user) properties, such as user name, etc. AppendixC 435 Random An instance generates a stream of pseudo-random numbers. TimeZone Instances represent time zones, such as GMT. SimpleTimeZone Defines a time zone for use with the Gregorian calendar class. Stack A basic stack type class, of which instances are growable. StringTokenizer Instances of this class allow a string to be broken down into tokens identified by delimiters (Le. space, period, etc.). Vector Implements a growable array of objects. C.3 THE INTERFACES Enumeration Instances which implement this interface generate a series of elements. Successive calls to the nextElement method return successive elements of the series. EventListener The root of all event listeners. Observer The common protocol for all classes which wish to take part in an observer-oberservable dependency relationship. C.4 THE EXCEPTIONS EmptyStackException Raised by the Stack class when asked to return a value from an empty stack. MissingResourceException Indicates that a resource is missing. NoSuchElementException Raised by a class implementing the Enumeration interface when the nextElement is sent and there are no remaining elements in the series. TooManyListenersException Thrown when only one listener may be registered on a particular event listener source, and more than one such registration is attempted. APPENDIXD The java.io Package D.1 INTRODualON ( DaIIlnput (:.:.j ( DaIIOulpui }..... \f--=-c--..,--J FIG. D.1 The java.io package 437 438 Java and Object Orientation The java.io package provides the basic input output facilities for the Java environment. Primarily this input output is built around the use of data streams. For example, to read data from a me, a stream is associated with that me and then the data in read from the stream. In general