Java Reference
In-Depth Information
Section 21.2 Self-Referential Classes
• A self-referential class (p. 871) contains a reference that refers to another object of the same class
type. Self-referential objects can be linked together to form dynamic data structures.
Section 21.3 Dynamic Memory Allocation
• The limit for dynamic memory allocation (p. 871) can be as large as the available physical mem-
ory in the computer or the available disk space in a virtual-memory system. Often the limits are
much smaller, because the computer's available memory must be shared among many users.
• If no memory is available, an OutOfMemoryError is thrown.
Section 21.4 Linked Lists
• A linked list is accessed via a reference to the first node of the list. Each subsequent node is ac-
cessed via the link-reference member stored in the previous node.
• By convention, the link reference in the last node of a list is set to null to mark the end of the list.
• A node can contain data of any type, including objects of other classes.
• A linked list is appropriate when the number of data elements to be stored is unpredictable.
Linked lists are dynamic, so the length of a list can increase or decrease as necessary.
• The size of a “conventional” Java array cannot be altered—it's fixed at creation time.
• List nodes normally are not stored in contiguous memory. Rather, they're logically contiguous.
• Packages help manage program components and facilitate software reuse.
• Packages provide a convention for unique type names that helps prevent naming conflicts (p. 884).
• Before a type can be imported into multiple programs, it must be placed in a package. There can
be only one package declaration (p. 883) in each Java source-code file, and it must precede all
other declarations and statements in the file.
• Every package name should start with your Internet domain name in reverse order. After the do-
main name is reversed, you can choose any other names you want for your package.
• When compiling types in a package, the javac command-line option -d (p. 884) specifies where to
store the package and causes the compiler to create the package's directories if they do not exist.
•The package name is part of the fully qualified type name (p. 884).
• A single-type-import declaration (p. 885) specifies one class to import. A type-import-on-demand
declaration (p. 885) imports only the classes that the program uses from a particular package.
• The compiler uses a class loader (p. 885) to locate the classes it needs in the classpath. The classpath
consists of a list of directories or archive files, each separated by a directory separator (p. 885).
• The classpath for the compiler and JVM can be specified by providing the -classpath option
(p. 886) to the javac or java command, or by setting the CLASSPATH environment variable. If
classes must be loaded from the current directory, include a dot ( . ) in the classpath.
Section 21.5 Stacks
• A stack is a last-in, first-out (LIFO) data structure (p. 886). The primary methods used to ma-
nipulate a stack are push (p. 887) and pop (p. 887), which add a new node to the stack's top and
remove a node from the top, respectively. Method pop returns the removed node's data.
• When a method call is made, the called method must know how to return to its caller, so the
return address is pushed onto the program-execution stack. If a series of method calls occurs, the
successive return values are pushed onto the stack in last-in, first-out order.
• The program-execution stack contains the space created for local variables on each invocation of
a method. When the method returns to its caller, the space for that method's local variables is
popped off the stack, and those variables are no longer available to the program.
Search WWH ::




Custom Search