CHAPTER 20: The Package java.lang |
![]() Previous |
![]() Java Language |
![]() Index |
![]() Next |
The java.lang package contains classes that are fundamental to the design of the Java language. The most important classes are Object (S20.1), which is the root of the class hierarchy, and Class (S20.3), instances of which represent classes at run time.
Frequently it is necessary to represent a value of primitive type as if it were an object. The class Number (S20.6) contains wrapper classes Boolean (S20.4), Character (S20.5), Integer (S20.7), Long (S20.8), Float (S20.9), and Double (S20.10) that serve this purpose. An object of type Double, for example, contains a field whose type is double, representing that value in such a way that a reference to it can be stored in a variable of reference type. These classes also provide a number of methods for converting among primitive values, as well as supporting such standard methods as equals and hashCode.
The class Math (S20.11) provides commonly used mathematical functions such as sine, cosine, and square root. The classes String (S20.12) and StringBuffer (S20.13) similarly provide commonly used operations on character strings.
Classes ClassLoader (S20.14), Process (S20.15), Runtime (S20.16), SecurityManager (S20.17), and System (S20.18) provide "system operations" that manage the dynamic loading of classes, creation of external processes, host environment inquiries such as the time of day, and enforcement of security policies. The classes Thread (S20.20) and ThreadGroup (S20.21) and the interface Runnable S20.19 also provide important management operations.
Class Throwable (S20.22) encompasses objects that may be thrown by the throw statement (S14.16). Subclasses of Throwable represent errors and exceptions.
The hierarchy of classes defined in package java.lang is as follows.
Object interface Cloneable Class Boolean Character Number Integer Long Float Double Math String StringBuffer ClassLoader Process Runtime SecurityManager System interface Runnable Thread ThreadGroup Throwable Error LinkageError ClassCircularityError ClassFormatError ExceptionInInitializerError IncompatibleClassChangeError AbstractMethodError IllegalAccessError InstantiationError NoSuchFieldError NoSuchMethodError NoClassDefFoundError UnsatisfiedLinkError VerifyError VirtualMachineError InternalError OutOfMemoryError StackOverflowError UnknownError ThreadDeath Exception ClassNotFoundException CloneNotSupportedException IllegalAccessException InstantiationException InterruptedException RuntimeException ArithmeticException ArrayStoreException ClassCastException IllegalArgumentException IllegalThreadStateException NumberFormatException IllegalMonitorStateException IndexOutOfBoundsException NegativeArraySizeException NullPointerException SecurityException