Stack Array Based

Stack Array Based
Java Implementation
Server

This project implements a basic stack data structure and REST API using Java and Spring Boot. At the core is an ArrayBasedStack generic class that handles push, pop, peek, and other stack operations. It leverages an object array to store elements and a top index to track the stack state.

To expose the stack functionality over HTTP, a Spring @RestController class called StackController is implemented. It provides endpoints like /push, /pop, and /peek that tie to the underlying ArrayBasedStack methods, returning HTTP responses that include status codes and messages based on the outcome. Additional endpoints like /isEmpty and /isFull check and return the stack state.

The project is built using Spring Boot for easy standalone deployment. It includes exception handling via a custom StackException class, default values, and validation logic to prevent issues like overflow. Support for converting the internal array to a List is also provided for endpoints that return the full server-side stack contents.

This is a simple model Spring Boot web service that implements an array-based stack for demonstration and learning purposes. Both the core data structure and REST interface exposing it are included, making it an effective hands-on example of these concepts.

View the Server Side Code on GitHub.
Heroku

Heroku plays a key role in hosting and connecting the front-end JavaScript interface to the Java Spring Boot backend API.

The Maven backend jar can be pushed to Heroku with a simple git push.

Heroku will automatically build the necessary assets and serve them from an app URL. It handles downloading Java dependencies from the Pom.xml file and building the Spring Boot executable jar.

The frontend JavaScript application can then seamlessly access the Java API endpoints by configuring the baseUrl variable to the backend Heroku app URL route. No servers need to be configured or linked manually.

This is an extremely convenient cloud-hosted architecture for modern JavaScript + Java web apps. Heroku builds and bundles both pieces automatically while handling all hosting, scaling, and linking between the front end and back end.

I can focus on coding, while Heroku streamlines the full stack deployment process – perfect for quickly demoing or iterating on these types of projects.

Front End

The front end provides a visual interface for interacting with the Spring Boot stack web service implemented previously. It allows pushing and popping items from the stack visually and seeing the changes reflected in an SVG visualization dynamically updated with D3.js.

Some key components:

SVG element to visualize the stack contents as colored rectangles. Input fields and buttons to trigger stack operations. Fetch calls to the backend endpoints like /push and /pop. refreshStack() to sync visualization with the actual stack. Logging/error handling for API responses. Responsively designed for mobile.

When actions like push and pop occur, the front-end interface handles calling the API, processes the response, logs any errors, and updates the SVG stack visualization by removing or adding rectangles. This creates a smooth user experience for testing the stack capabilities.

The interface is intentionally kept simple and clean to enable easy demonstration and learning. It provides a nice complement to the back-end REST API, allowing visual inspection of the stack operations.

Overall, it delivers an interactive visual frontend to play with the array-based stack implementation and supplements the server-side capabilities discussed previously.

View the Front End Code on GitHub.

Posted

in

by

Tags: