Select this to skip to main content [CSUSB] >> [CNS] >> [Comp Sci Dept] >> [R J Botting] >> [CS320 Course Materials] >> [Java] >> java.classes [Source]
[Index] [Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Search] [Grading]
Thu Jan 22 13:43:04 PST 2004


    The Predefined Classes in Java

      Much of the usefulness of Java comes from the packages of useful classes. objects, and functions that already exist.

      The class library is still evolving - We hav got as far as 1.0.2. Your class library may be different - see your own local documentation. For example on the Sun Workstations at (only) see //localhost/usr/local/hotjava/doc/api/packages.html for the real skinny.

      The class library from an API.

    1. API::=Application Programmers Interface. In otherwords it is intended that you should use these to do most of the standard stuff - GUI interfaces, networking, audio, and so on. Mor interesting is that the same code will automatically assume the look-and-feel of the client machine. If someone is using Windows 95 then they will see the usual file open dialogue. On UNIX it will look like a UNIX dialogue, and on a Mac like a Mac Dialogue. Even the form of buttons will be adjusted to what the client expects (not what you think is right:-).

      The following pointers are to descriptions of the current release of the Java classes.

      JavaSoft API Documentation

      The classes are grouped into packages - this means that they can share certain mtheods and field not available thru the API.
        Index [ ] and list of packages [ Package.html ]

        Class Hierarchy

        [ tree.html ] or locally [ java.class.tree.html ]

        Language Foundation Classes

        Package java.lang contains essential Java classes, including numerics, strings, objects, compiler, runtime, security and threads. Unlike other packages, java.lang is automatically imported into every Java program. [ Package-java.lang.html ]

        Input/Output package

        Package provides a set of input and output streams to read and write data to files, strings, and other sources. [ ]

        Utility Class Library

        Package java.util contains miscellaneous utility classes, including generic data structures, settable bits class, time, date, string manipulation, random number generation, system properties, notification, and enumeration of data structures. [ Package-java.util.html ]

        Abstract Window Toolkit Library

        Package java.awt provides user interface features such as windows, dialog boxes, buttons, checkboxes, lists, menus, scrollbars and text fields. It is said to be Abstract because it is device and operating system independent - much to the irritation of some programmers who take their revenge by inventing other meanings for the acronym. [ AWT ] below and [ Package-java.awt.html ]


        Package java.applet enables construction of applets. It also provides information about an applet's parent document, about other applets in that document, and enables an applet to play audio. See [ Applet ] below and [ Package-java.applet.html ]

        Network Interface Class Library

        Package network support, including URLs, TCP sockets, UDP sockets, IP addresses and a binary-to-text converter. [ ]

        Images - Audio and Visual

        Package java.image is for managing image data, such as the setting the color model, cropping, color filtering, setting pixel values and grabbing snapshots.


      Two question marks ?? [ 1_below ] indicate that I haven't found the data yet. If you have found the answer in any offical documentation please send it to where it will be incorporated with an acknowledgement.

      These are working notes and are being revised daily. Again I am open to corrections and improvements.

      Data Types

      [ java.semantics.html ]

      Object Hierarchy


            For all C:Class, ob:Object, ob instanceof C::Boolean.
          1. Object()::constructor.
          2. methods: clone() equals() finalize() getClass() hashCode() notify()
          3. notifyAll() toString() wait(long) wait(long,int) wait()


              public final class System extends Object in package java.lang.System

              This provides a system-independent model of the operating system. It includes the standard input and output streams for example. The standard input streams are used for reading character data. The standard output streams are used for printing. For example:

               		System.out.println("Hello World!");

              The System Class represents a single and predefined real object. So it cannot have objects of type System(instances) Nor can it be subclassed.

              System Variables

            1. err::=Standard Error Reporting Stream::PrintStream. [ PrintStream ]
            2. out::=Standard Output stream:: PrintStream. [ PrintStream ]
            3. in::=Standard Input stream::InputStream. [ InputStream ] and [ DataInputStream ]

              System Methods

              1. arraycopy(Object, int, Object, int, int)::= Copies an array from the source array, beginning at the specified position, to the specified position of the destination array.
              2. exit(int)::= Exits the virtual machine with an exit code. [ Array Copy ]
              3. currentTimeMillis()::= Returns the current time in milliseconds GMT since the epoch (00:00:00 UTC, January 1, 1970). See Also [ Date ]
              4. gc()::= Runs the garbage collector.
              5. getProperties()::= Gets the System properties.
              6. getProperty(String)::= Gets the System property indicated by the specified key.
              7. getProperty(String, String)::= Gets the System property indicated by the specified key and def.
              8. getSecurityManager()::= Gets the system security interface.
              9. load(String)::= Loads a dynamic library, given a complete path name.
              10. loadLibrary(String)::= Loads a dynamic library with the specified library name.
              11. runFinalization()::= Runs the finalization methods of any objects pending finalization.
              12. setProperties(Properties)::= Sets the System properties to the specified properties.
              13. setSecurityManager(SecurityManager)::= Sets the System security.

                Array Copy

                    public static void arraycopy(Object from_source, int from_source_position,
                                                 Object to_destination, int to_destination_position,
                                                 int length)
                  Precondition: Both arrays exist and have space for at least length objects.

                  Postcondition: First length Objects in the second array equal those in first array.

                  Invariant: The first array.

              . . . . . . . . . ( end of section System Methods) <<Contents | Index>>


              public final class java.awt.Color extends java,lang.Object [ java.awt.Color.html ]
            1. colors::={ black, blue, cyan,darkGray, gray, green, lightGray, magenta, orange, pink, red, white, yellow}.
            2. Color(float red, float green, float blue)::constructor.
            3. Color(int red, int green, int blue)::constructor.
            4. Color(int rgb)::constructor.
            5. color.getBlue()::int, gets commponent of color.
            6. color.getGreen()::int, gets one component of color.
            7. color.getRed()::int, gets one component of color. ...


              public class PrintStream extends Object
            1. println(String)


              public class InputStream extends Object For example the standard input [ in ] An abstract class representing an input stream of bytes. All InputStreams are based on this class.
            1. InputStream(), available(), close(), mark(int), markSupported(), read(), read(byte[]), read(byte[], int, int), reset(), skip(long)



                  By creating one of these from an unformatted input stream [ InputStream ] you can attempt to read in simple data types from the resulting stream.
                1. DataInputStream(InputStream in)::=Creates a new DataInputStream.
                2. For S:DataInputStream, S.readLine()::String=returns a String copy of the line. For S:DataInputStream, S.readFully(byte[] b)::reads until blocked into b. For S:DataInputStream, X:{ Boolean, Byte, Char, Double, Float, Long, Short, UTF, unsignedByte, unsignedShort},S.readX()::X=Reads and returns an X.


              For each class there is an associated class of arrays. An array has a set of elements of the same class number from 0 to some fixed length. The elements of array a are written a[0], a[1], . . . , a[a.length-1]. Arrays have a fixed length once created. This is accessable as an field named length of each array:
            1. length_of_array_a::= a.length.

              Vectors [ java.util.Vector.html ] expand when needed.

              For all C:Classes, A:Classes=array_of_C, i:identifier, e:expression, a:array_of_C, v:array_of_C_variable, ec:C expression, C []::Classes=class of arrays of objects of class C::=A, C [] i::declaration=declare_an_array_of_C, C i []::declaration=declare_an_array_of_C, v=a::expression(A)=afterwards v refers to array a, v[e]=ec::expression(C)=afterwards the element of v has value ec but no other elements of v have been effected, new C [ e ]::expression(A)=a new array of e C's, a.length::int=number of items of class C in array a, a[e]::expression(C)=the element of array a, (C[])ec::expression(A)=an array with element ec of length 1?? [ 1_below ]

              For all A:Classes, B:subclasses(A), B[] in subclasses(A[]).

              For arrays of characters see character strings [ String and StringBuffer ]

              For arrays indexed by general objects see hash tables [ HashTable ]

            String and StringBuffer

              (String): A general class of objects to represent character Strings. Strings are constant, their values cannot be changed after creation. [ java.lang.String.html ]
            1. literal::= double_quotes string double_quotes.
            2. infix::={"+"}. -- concatenation. -- hence "+="
            3. String()::=construct new empty string. String(String), String(char[]), String(char[],int,int), String(byte[], int ,int,int), String(byte[], int), String(StringBuffer)::=Construct new String copying various data.
            4. charAt(int)::=character at (_).
            5. compareTo(String)::int=lexographic comparison return <0 if <, 0 if equal and >0 if >. See C.strcmp.
            6. concat(String)::=Place (_) at end of this String.
            7. copyValueOf, endsWith, hashCode(String), intern,
            8. equals(String)::boolean=This string is the same as (_).
            9. equalsIgnoreCase(String)::boolean,
            10. getBytes(int,int,byte[],int)::=Copy into (3rd),
            11. getChars(int,int,char[],int)::=copies chars into (3rd).
            12. indexOf(...)::int=position of first matching (_) in this string.
            13. lastIndexOf(...)::int=position of last matching (_) in this string.
            14. length()::int=number of chars/bytes in string.
            15. ... substring(int), substring(int,int)::String=substrings of this string.
            16. toCharArray(), toLowerCase(), toString, toUpperCase,
            17. trim()::=remove leading and trailing whitespace.
            18. valueOf(...)::=String object cantain representation of (_).

                (StringBuffer): This Class is a growable buffer for characters. It is mainly used to create Strings. But can append any kind of Object which is ?? [ 1_below ] converted into a sequence of characters before being added to the buffer, StringBuffer(...) creates Strings and StringBuffer append(Object obj) adds an object to the end of this buffer and returns the StringBuffer itself [ java.lang.StringBuffer.html ]
              1. append(...)::=Put (_) after the last character of this string.
              2. capacity()::=capcity of theis string.
              3. ensureCapacity(int)::=Make sure room for (_) chars.
              4. charAt(), getChars(),
              5. insert(int, X)::=Inserts an X into the buffer.
              6. length()::int=number chars in this string buffer.
              7. setCharAt(int, char)::=change this string's (1st) char to (2nd). setLength(int::=Set length to (_) chars,
              8. toString()::=converstbuffered data to String.


              The Dictionary class is the abstract [ abstract in java.semantics ] parent of Hashtable, which maps keys to values. Any object can be used as a key and/or value. Any Object has a hashCode(_).
            1. Dictionary() elements() get(Object) isEmpty() keys() put(Object, Object) remove(Object) size()


              [ java.util.Vector.html ]


              Stacks [ java.util.Stack.html ] are Vectors that can accessed at only one end - the "top" - by push() and pop() operations. [ java.util.Stack.html ]


              Number [ java.lang.Number.html ] is an abstract superclass for numeric scalar types, like (Integer): fixed(16.bits, signed),
              (Long): fixed(32.bits, signed),
              (Float): floating_point(16.bits,IEEE) and (Double):(32,bits, IEEE): are subclasses of Number [ numeric. in java.semantics ] Each of these provides a method for extracting the basic data type from the object: (int intValue(Integer), double doubleValue(Double), float floatValue(Float), long longValue(Long)), and a constructor for making the Object from its data ( Integer(int), Long(long),....).


              (Math Constants): E, PI
              (Math Functions): abs acos asin atan atan2 ceil cos exp floor log max min pow randon rint round sin sqrt tan

              Warning: the behavior specified for mathematical functions is implementation dependent. For example they are supposed to throw an exception when the answer is not a number (eg sqrt(-1)). However they have been implemented as calling the standard C library functions and so return Double.NaN(Double's IEEE Not-a-Number value).


            1. forName(String) getClassLoader() getInterfaces() getName()
            2. getSuperclass() isInterface() newInstance() toString()


              AWT Component
              1. action(Event,Object) addNotify()
              2. bounds()
              3. checkImage(Image, ImageObserver) checkImage(Image, int, int, ImageObserver) createImage(int, int)
              4. deliverEvent(Event) disable()
              5. enable() enable(boolean) getBackground() getColorModel() getFont() getFontMetrics(Font) getForeground() getGraphics() getParent() getPeer() getToolkit() gotFocus(Event, Object)
              6. handleEvent(Event) hide()
              7. imageUpdate(Image, int, int, int, int, int) inside(int, int) invalidate() isEnabled() isShowing() isValid() isVisible()
              8. keyDown(Event, int) keyUp(Event, int)
              9. layout() list() list(PrintStream) list(PrintStream, int) locate(int, int) location() lostFocus(Event, Object)
              10. minimumSize() mouseDown(Event, int, int) mouseDrag(Event, int, int) mouseEnter(Event, int, int) mouseExit(Event, int, int) mouseMove(Event, int, int) mouseUp(Event, int, int) move(int, int)
              11. nextFocus()
              12. paint(Graphics) paintAll(Graphics) paramString() postEvent(Event) preferredSize() prepareImage(Image, ImageObserver) prepareImage(Image, int, int, ImageObserver) print(Graphics) printAll(Graphics)
              13. removeNotify() repaint() repaint(long) repaint(int, int, int, int) repaint(long, int, int, int, int) requestFocus() reshape(int, int, int, int) resize(int, int) resize(Dimension)
              14. setBackground(Color) setFont(Font) setForeground(Color) show() show(boolean) size()
              15. toString()
              16. update(Graphics)
              17. validate()

                AWT Container

                1. add(Component) add(Component, int) add(String, Component) addNotify()
                2. countComponents()
                3. deliverEvent(Event) getComponent(int)
                4. getComponents() getLayout()
                5. insets()
                6. layout() list(PrintStream, int) locate(int, int) minimumSize()
                7. paintComponents(Graphics) paramString() preferredSize() printComponents(Graphics)
                8. remove(Component) removeAll() removeNotify()
                9. setLayout(LayoutManager)
                10. validate() AWT Panel
                  1. Panel() addNotify()

                  . . . . . . . . . ( end of section AWT) <<Contents | Index>>


                  1. Applet()
                  2. destroy()
                  3. getAppletContext() getAppletInfo()
                  4. getAudioClip(URL) getAudioClip(URL, String) getDocumentBase() getImage(URL) getImage(URL, String) getParameter(String) getParameterInfo()
                  5. init() isActive()
                  6. play(URL) play(URL, String)
                  7. resize(int, int) resize(Dimension)
                  8. setStub(AppletStub) showStatus(String) start() stop()

        . . . . . . . . . ( end of section Object) <<Contents | Index>>

      . . . . . . . . . ( end of section Object Hierarchy) <<Contents | Index>>

    . . . . . . . . . ( end of section The Predefined Classes in Java) <<Contents | Index>>

    End Notes

      (1_below): Indicates something that I think is true but have not been able to check please sen mail to to either confirm or deny the opeinion expressed thereafter.

    . . . . . . . . . ( end of section End Notes) <<Contents | Index>>

Formulae and Definitions in Alphabetical Order