Thursday, July 30, 2009

Data Type, Abstract Data Type and Data Structure

Data type refers to the to the kind of data that variables can assume, hold or take on in a programming language and for which operations are automatically provided. In Java, the primitive data types are:
Keyword    Description

byte Byte-length integer
short Short integer
int Integer
long Long integer
float Single-precision floating point
double Double-precision floating point
char A single character
boolean A boolean value (true or false)
Java Tutorial: Data Type, Abstract Data Type and Data Structure

Abstract Data Type (ADT), on the other hand, is a mathematical model with a collection of operations defined on the model. It specifies the type of data stored. It specifies what its operations do but not how it is done. In Java, ADT can be expressed with an interface, which contains just a list methods. For example, the following is an interface of the ADT stack, which we will cover in detail in Chapter 2:

public interface Stack{
public int size(); /* returns the size of the stack */
public boolean isEmpty(); /* checks if empty */
public Object top() throws StackException;
public Object pop() throws StackException;
public void push(Object item) throws StackException;
}

Java Tutorial: Data Type, Abstract Data Type and Data Structure

Data structure is the implementation of ADT in terms of the data types or other data structures. A data structure is modeled in Java by a class. Classes specify how operations are performed. In Java, to implement an ADT as a data structure, an interface is implemented by a class.

Abstraction and representation help us understand the principles behind large software systems. Information-hiding can be used along with abstraction to partition a large system into smaller subsystems with simple interfaces that makes them easier to understand and use.

No comments:

Post a Comment