Java The Complete Reference, Seventh Edition

(Greg DeLong) #1

Chapter 16: Exploring java.lang 435


This method reads characters intobuf.It returns the number of characters read, or –1 if an
EOF is encountered.

The java.lang Subpackages


Java defines several subpackages:


  • java.lang.annotation

  • java.lang.instrument

  • java.lang.management

  • java.lang.ref

  • java.lang.reflect


Each is briefly described here.

java.lang.annotation


Java’s annotation facility is supported byjava.lang.annotation. It defines theAnnotation
interface, and theElementTypeandRetentionPolicyenumerations. Annotations are described
in Chapter 12.

java.lang.instrument


java.lang.instrumentdefines features that can be usedto add instrumentationto variousaspects
of program execution. It defines theInstrumentationandClassFileTransformerinterfaces, and
theClassDefinitionclass.

java.lang.management


Thejava.lang.managementpackage provides management support for the JVM and the
execution environment. Using the features injava.lang.management, you can observe and
manage various aspects of program execution.

java.lang.ref


You learned earlier that the garbage collection facilities in Java automatically determine when
no references exist to an object. The object is then assumed to be no longer needed and its
memory is reclaimed. The classes in thejava.lang.refpackage provide more flexible control
over the garbage collection process. For example, assume that your program has created
numerous objects that you want to reuse at some later time. You can continue to hold references
to these objects, but that may require too much memory.
Instead, you can define “soft” references to these objects. An object that is “softly reachable”
can be reclaimed by the garbage collector, if available memory runs low. In that case, the
garbage collector sets the “soft” references to that object tonull. Otherwise, the garbage
collector saves the object for possible future use.
A programmer has the ability to determine whether a “softly reachable” object has been
reclaimed. If it has been reclaimed, it can be re-created. Otherwise, the object is still available
for reuse. You may also create “weak” and “phantom” references to objects. Discussion of
these and other features of thejava.lang.refpackage is beyond the scope of this book.
Free download pdf