20. The Package java.lang

CHAPTER 20

The Package java.lang

The java.lang package contains classes that are fundamental to the design of the Java language. The most important classes are Object, which is the root of the class hierarchy, and Class, 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 wrapper classes Boolean, Character, Integer, Long, Float, and Double 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 provides commonly used mathematical functions such as sine, cosine, and square root. The classes String and StringBuffer similarly provide commonly used operations on character strings.

Classes ClassLoader, Process, Runtime, SecurityManager, and System 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.

Class Throwable encompasses objects that may be thrown by the throw statement (§14.16). Subclasses of Throwable represent errors and exceptions.

The hierarchy of classes defined in package java.lang is as follows.

Object§20.1interface Cloneable§20.2 Class§20.3   Boolean§20.4 Character§20.5   Number§20.6      Integer§20.7     Long§20.8        Float§20.9       Double§20.10 Math§20.11   String§20.12 StringBuffer§20.13   ClassLoader§20.14    Process§20.15    Runtime§20.16    SecurityManager§20.17    System§20.18interface Runnable§20.19    Thread§20.20 ThreadGroup§20.21    Throwable§20.22      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