Exploring java.lang

This chapter discusses those classes and interfaces defined laborsaving. As you know, java.lang is automatically imported into all programs. It contains classes and interfaces that are fundamental to virtually all of Java programming. It is java’s most widely used package. java.lang includes the following classes:

In addition, there are two classes defined by Character: Character.Subset and’ Character Nickelodeon. These were added by Java 2. java.lang also defines the following interfaces: Ia Clone able Comparable Burnable ‘” The Comparable insolence was added by Java 2. Several of the classes contained in java.lang contain deprecated methods, most dating back to Java 1.0. These deprecated methods are still provided by java 2, to support an ever-shrinking pool of legacy code, and are not recommended for new code. Most of the deprecation took place prior to Java 2 and these deprecated methods are not discussed here. Deprecation that occurred because of lava 2, however, are mentioned .., Java 2 also adds several new classes and method’) to the java.lang package The new additions arc so indicated.

Simple Type Wrappers

As we mentioned in Par+ I of this book, Java uses simple types, such as int and char, for performance reasons. These data types are net part of the object hierarchy. They are passed by value to methods and cannot be directly passed by reference. Also, there is no way for two methods to refer to the same instance of an int. At times, you will need to create an object representation for one of these simple types. for example, there arc enumeration classes discussed in Chapter 15 that deal only with objects; to store a simple type in one of these classes, you need to wrap the simple type in a class. To address this need, Java provides classes that correspond to each of the simple types. In essence, these classes encapsulate, or wrap, the simple types within a class. Thus, they are commonly referred to as type wrappers.

[vfb id=1]

Share This