Java Reference
In-Depth Information
Chapter 7. Structuring Data with Java
Introduction
Almost every application beyond “Hello World” needs to keep track of some structured data.
A simple numeric problem might work with three or four numbers only, but most applica-
tions have groups of similar data items. A GUI-based application may need to keep track of a
number of dialog windows. A personal information manager, or PIM, needs to keep track of
a number of, well, persons. An operating system needs to keep track of who is allowed to log
in, who is currently logged in, and what those users are doing. A library needs to keep track
of who has books checked out and when they're due. A network server may need to keep
track of its active clients. A pattern emerges here, and it revolves around variations of what
has traditionally been called data structuring.
There are data structures in the memory of a running program; there is structure in the data in
a file on disk, and there is structure in the information stored in a database. In this chapter,
we concentrate on the first aspect: in-memory data. We'll cover the second aspect in
Chapter 10 and the third in Chapter 18 .
If you had to think about in-memory data, you might want to compare it to a collection of in-
dex cards in a filing box, or to a treasure hunt where each clue leads to the next. Or you
might think of it like my desk—apparently scattered, but actually a very powerful collection
filled with meaningful information. Each of these is a good analogy for a type of data struc-
turing that Java provides. An array is a fixed-length linear collection of data items, like the
card filing box: it can only hold so much, then it overflows. The treasure hunt is like a data
structure called a linked list . The first releases of Java had no standard linked list class, but
you could write your own “traditional data structure” classes (and still can; you see a DIY
Linked List implementation in Structuring Data in a Linked List ). The complex collection
represents Java's Collection classes. A document entitled Collections Framework Over-
view , distributed with the Java Development Kit documentation (and stored therein as file …/
docs/guide/collections/overview.html and online ), provides a detailed discussion of the Col-
lections Framework. The framework aspects of Java collections are summarized in The Col-
lections Framework .
Search WWH ::




Custom Search