Wednesday, March 11, 2026
Cart / 0 $

No products in the cart.

  • Login
  • Register
Bawabaa Digital Solutions
No Result
View All Result
  • Home
  • Products
    • Unlock Premium Access
    • Subscriptions
  • About
    • Terms and conditions
    • Privacy Policy
    • Refund Policy
  • Contact
  • Posts
  • Home
  • Products
    • Unlock Premium Access
    • Subscriptions
  • About
    • Terms and conditions
    • Privacy Policy
    • Refund Policy
  • Contact
  • Posts
No Result
View All Result
Bawabaa Digital Solutions
Home Main

The difference between Data Type, Abstract Data Type (ADT), and Data Structure in Java

Published on: February 9, 2026
Updated on: February 11, 2026

To illustrate the differences between Data Type, Abstract Data Type (ADT), and Data Structure in Java, let’s use the example of a Stack. Below, I’ll provide code snippets for each concept:


1. Data Type in Java

A data type defines the type of data a variable can hold and the operations that can be performed on it. In Java, data types can be primitive (e.g., int, float) or reference types (e.g., String, Object).

Example: Primitive Data Type (int)

int number = 10; // 'int' is a primitive data type
number = number + 5; // Operation: addition
System.out.println(number); // Output: 15

Example: Reference Data Type (String)

String name = "Alice"; // 'String' is a reference data type
name = name.toUpperCase(); // Operation: convert to uppercase
System.out.println(name); // Output: ALICE

2. Abstract Data Type (ADT) in Java

An ADT is a high-level description of data and operations. In Java, an ADT is typically defined as an interface or an abstract class. It specifies what operations can be performed, but not how they are implemented.

Example: Stack ADT (Interface)

public interface StackADT<T> {
    void push(T element); // Add an element to the stack
    T pop();              // Remove and return the top element
    T peek();             // Return the top element without removing it
    boolean isEmpty();    // Check if the stack is empty
    int size();           // Return the number of elements in the stack
}

This interface defines the behavior of a stack (what it can do), but it does not specify how the stack is implemented.


3. Data Structure in Java

A data structure is the concrete implementation of an ADT. In Java, this is typically a class that implements the ADT interface or provides the logic for storing and manipulating data.

Example: Stack Data Structure (Using an Array)

public class ArrayStack<T> implements StackADT<T> {
    private T[] stackArray; // Array to store stack elements
    private int top;        // Index of the top element
    private int capacity;   // Maximum capacity of the stack

    // Constructor
    public ArrayStack(int capacity) {
        this.capacity = capacity;
        this.stackArray = (T[]) new Object[capacity]; // Create array of generic type
        this.top = -1; // Stack is initially empty
    }

    // Push operation
    @Override
    public void push(T element) {
        if (top == capacity - 1) {
            throw new IllegalStateException("Stack is full");
        }
        stackArray[++top] = element; // Add element to the top
    }

    // Pop operation
    @Override
    public T pop() {
        if (isEmpty()) {
            throw new IllegalStateException("Stack is empty");
        }
        return stackArray[top--]; // Remove and return the top element
    }

    // Peek operation
    @Override
    public T peek() {
        if (isEmpty()) {
            throw new IllegalStateException("Stack is empty");
        }
        return stackArray[top]; // Return the top element
    }

    // Check if stack is empty
    @Override
    public boolean isEmpty() {
        return top == -1;
    }

    // Return the size of the stack
    @Override
    public int size() {
        return top + 1;
    }
}

This class provides the implementation of the StackADT interface using an array as the underlying data structure.


Putting It All Together

Here’s how the three concepts work together in Java:

  1. Data Type: The stack uses a generic type T to store elements. For example, T could be Integer, String, or any other data type.
  2. ADT: The StackADT interface defines the operations (push, pop, peek, etc.).
  3. Data Structure: The ArrayStack class implements the StackADT interface using an array to store and manipulate data.

Example Usage:

public class Main {
    public static void main(String[] args) {
        StackADT<Integer> stack = new ArrayStack<>(5); // Create a stack of integers

        stack.push(10); // Push 10
        stack.push(20); // Push 20
        stack.push(30); // Push 30

        System.out.println(stack.pop()); // Output: 30 (LIFO behavior)
        System.out.println(stack.peek()); // Output: 20 (Top element is 20)
        System.out.println(stack.size()); // Output: 2 (Stack has 2 elements)
    }
}

Key Differences in Code

ConceptCode ExamplePurpose
Data Typeint number = 10; or String name = "Alice";Defines the type of data and basic operations.
ADTStackADT<T> interface with push, pop, peek, etc.Defines the behavior of a data type (what operations are possible).
Data StructureArrayStack<T> class implementing StackADT<T> using an array.Provides the concrete implementation of the ADT (how operations are done).

Summary

  • Data Type: Defines the type of data (e.g., int, String).
  • ADT: Defines the behavior of a data structure (e.g., StackADT interface).
  • Data Structure: Implements the ADT (e.g., ArrayStack class).

This separation allows for flexibility and modularity in designing and using data structures in Java.

Donation

Buy author a coffee

Donate
Share9Tweet6Share2
Previous Post

List of Curated Edtech Websites

Next Post

Introduction to Programming Languages

MOUSTAFA

MOUSTAFA

Technology, Engineering and Business Analyst

Categories

  • Main (78)

Recent Posts

  • WordPress Main Subjects – Complete Overview of Core Topics
  • How to Build a Multilingual WordPress Website: Methods, Pros, and Cons
  • Website / Project Development Hierarchy
  • WordPress Hooks Explained: Actions and Filters for Beginners
  • Software Adaptation Maturity Model SAMM
  • What is Screaming Architecture?
  • WordPress Deployment on AWS EC2 (Red Hat / Amazon Linux)
  • eCommerce Platforms Directory: List of Providers by Domain
  • Understanding Modules, Packages, Components, Libraries, Frameworks and Dependencies in Software Design
  • List of Curated YouTube Playlists
  • WordPress Conceptual System Model
  • Computer Science Courses on YouTube
  • Web Hosting Platforms Directory: List of Providers by Domain
  • Computation Theory
  • Software Building Blocks: A Modern Dev Guide
  • Software Architecture and Design
  • List Of Curated Websites
  • WordPress Development Services
  • WordPress Full Courses on YouTube
  • The “Green Padlock” on Localhost Cheat Sheet

HTML Content Title

  • Home
  • Products
  • About
  • Contact
  • Posts
WhatsApp: +201111128344

Bawabaa.com

Welcome Back!

Sign In with Google
OR

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Sign Up with Google
OR

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In

You cannot copy content of this page

  • Login
  • Sign Up
  • Cart
No Result
View All Result
  • Home
  • Products
    • Unlock Premium Access
    • Subscriptions
  • About
    • Terms and conditions
    • Privacy Policy
    • Refund Policy
  • Contact
  • Posts
SAVED POSTS

Bawabaa.com

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?