Basic Java Data Structures

last updated 1/19/07

Data

The representation of information in a manner suitable for communication or analysis by humans or machines

Data are the nouns of the programming world:

 

 

 


Data Type

A category of data characterized by the supported elements of the category and the supported operations on those elements

A language's set of primitive types (Java's are byte, char, short, int, long, float, double, and boolean) are not sufficient, by themselves, for dealing with data that have many parts and complex interrelationships among those parts.

Data structures provide this ability.

 

Definitions

Type examples


Definitions

Data abstraction The separation of a data type’s logical properties from its implementation

Data encapsulation The separation of the representation of data from the applications that use the data at a logical level; a programming language feature that enforces information hiding

Abstract data type (ADT) A data type whose properties (domain and operations) are specified independently of any particular implementation

Data Structure A collection of data elements whose logical organization reflects a relationship among the elements

 


Basic Operations on Encapsulated Data

A constructor is an operation that creates a new instance (object) of the data type.

Transformers (sometimes called mutators) are operations that change the state of one or more of the data values.

An observer (sometimes called an accessor) is an operation that allows us to observe the state of one or more of the data values with out changing them.

An iterator is an operation that allows us to process all the components in a data structure sequentially.

 

 

 


Data Levels of an ADTAbstraction Barrier

Logical (or abstract) level: Abstract view of the data values (the domain) and the set of operations to manipulate them.

Application (or user) level: Here the application programmer uses the ADT to solve a problem.

Implementation level: A specific representation of the structure to hold the data items, and the coding of the operations in a programming language.

Communication between the Application (user) Level and Implementation Level

Across an "Abstraction Barrier":

 

 

 


Java’s Built-In Types

Type Taxonomy

 


Implementation Dependent Structures

As primitive (read as built in) structures provided by a programming language, you have arrays and objects that reference other objects as in linked links.


Implementation Independent Structures

These data structures are more abstractly discussed.  They may be implemented with different underlying structures.

For example the stack and queue could be implemented either as a linked list or an array.


Basic Structuring Mechanisms

There are two basic structuring mechanisms provided in Java (and many other high level languages): arrays and references

References

 


The Java Class Construct

Can be a mechanism for creating composite data types.

Is composed of named data fields (class and instance variables) and methods.

Is unstructured because the meaning is not dependent on the ordering of the members.

Records

When a class is used strictly to hold data and does not hide the data.

We may look at these structures later.

 


Assignment Statement

Primitive Types versus Objects

 


Ramifications of Using References

Aliases—we have two names for the same object.  But consider


Comparison of objects

Comparison of primitive and non


Parameter Passing

This is a form of assignment--from the calling code to the called method.

 

 


Garbage Management

Garbage: The set of currently unreachable objects

Garbage collection: The process of finding all unreachable objects and deallocating their storage space

Deallocate: Return the storage space for an object to the pool of free memory so that it can be reallocated to new objects

Dynamic memory management: The allocation and deallocation of storage space as needed while an application is executing