Showing posts with label common_java. Show all posts
Showing posts with label common_java. Show all posts

Saturday, June 27, 2026

🧰 Building a Practical Java Utility Library: Exploring common_java

 When working across multiple Java applications, one problem appears again and again:

you keep rewriting the same “basic but essential” components.

common_java is a lightweight utility-style library that groups these repeated concerns into reusable modules — from validation and caching to HTTP, database helpers, and email utilities.

Let’s walk through what this library provides.

📦 1. Project Overview

The library is organized into clear functional packages:

  • validator → input validation logic
  • string → string utilities
  • cache → in-memory caching (including LRU cache)
  • network → HTTP and IP utilities
  • http → URL fetch example app
  • alert → email composition and sending
  • database → JDBC helpers and result handling
  • properties → config loading utilities

This is a classic “common utilities” architecture: each package solves a real-world repetitive backend problem.

✅ 2. Validation Layer

Key classes:

  • Validator
  • EmailValidator

This layer focuses on ensuring data correctness before processing.

Typical responsibilities:

  • checking input format
  • validating email structure
  • centralizing reusable validation rules

💡 Design idea:
Instead of scattering validation logic across services, it is centralized.

Example concept:

Validator.isNotNull(value);

EmailValidator.isValid(email);

🧵 3. String Utilities

Hex.java

This likely provides:

  • hex encoding / decoding
  • conversion between byte arrays and hex strings

💡 Why it matters:
Hex utilities are commonly needed in:

  • encryption
  • networking
  • debugging binary data

⚡ 4. Cache System (Most Interesting Part)

Core classes:

  • Cache
  • LRUCache
  • CacheElement
  • Node
  • LinkedListNode
  • DoublyLinkedList
  • DummyNode
  • CacheApp

🧠 What this module shows

This is a classic LRU Cache implementation using:

  • Hash-based lookup (likely via Cache)
  • Doubly linked list for ordering
  • Node abstraction for entries

🔁 LRU Cache concept

Least Recently Used (LRU) cache works like this:

  • Recently used items stay in memory
  • Old unused items are removed first

🧱 Data structure design

This design typically combines:

  • HashMap → O(1) access
  • Doubly Linked List → O(1) insert/remove

💡 Why multiple node classes?

  • Node → base structure
  • LinkedListNode → real element
  • DummyNode → sentinel node (simplifies edge cases)

This shows clean separation of concerns in data structure design.

🚀 Why this module stands out

This is not just a utility — it’s a fully custom cache engine, useful for:

  • performance optimization
  • memory control
  • backend caching strategies

🌐 5. Network Utilities

Classes:

  • HttpUtil
  • HttpClientApp
  • HttpResponse
  • HttpResponseCode
  • IP

What this module does

It likely provides:

  • HTTP GET/POST helpers
  • response wrapper object
  • HTTP status code abstraction
  • IP-related utilities

💡 Design strength

Instead of directly using low-level HTTP calls everywhere, the library:

✔ wraps HTTP logic
✔ standardizes response handling
✔ centralizes error handling

This improves consistency across projects.

📧 6. Email / Alert System

Classes:

  • Email
  • EmailAddress
  • EmailBody
  • EmailAttachment
  • SMTP
  • EmailApp

What this represents

A structured email system with:

  • strongly typed email components
  • separation of:
    • recipient (EmailAddress)
    • content (EmailBody)
    • attachments (EmailAttachment)
  • SMTP abstraction

💡 Why this design is good

Instead of passing raw strings:

sendEmail(to, subject, body)

You model email as an object:

Email email = new Email(...)

This improves:

  • readability
  • validation
  • maintainability

🗄️ 7. Database Utilities

Classes:

  • DatabaseManager
  • DatabaseStatementManager
  • StatementUtil
  • Jdbc
  • Result
  • RStoListMap

What this module solves

JDBC in Java is powerful but verbose.

This module likely simplifies:

  • connection handling
  • statement execution
  • result set mapping

💡 Key idea: abstraction over JDBC

Instead of repeating boilerplate:

Connection conn = ...
PreparedStatement stmt = ...
ResultSet rs = ...

You centralize it into utilities.

🔁 RStoListMap

This likely converts:

ResultSet → List<Map<String, Object>>

This is extremely useful for:

  • APIs
  • JSON conversion
  • dynamic queries

⚙️ 8. Configuration Utilities

ConfigApp

This likely handles:

  • loading .properties files
  • environment configuration
  • app-level settings

💡 Why it matters:

Every Java system needs config loading, and centralizing it avoids duplication.

🌍 9. HTTP Example App

UrlFetchApp

This is likely a demo or utility showing:

  • fetching URL content
  • using HttpUtil

This acts as:

a usage example of the network module

🧠 Overall Design Observations

✔ Strengths

1. Clear modular separation

Each package has a single responsibility.

2. Real-world utility coverage

It covers:

  • validation
  • caching
  • HTTP
  • email
  • database

This is basically a mini backend toolkit.

3. Strong focus on reusability

Everything is designed to be reused across projects.

🚀 Final Summary

common_java is essentially a personal backend utility framework that helps reduce repetitive Java boilerplate across projects.

It demonstrates:

  • practical backend engineering patterns
  • data structure implementation (LRU cache)
  • abstraction over JDBC and HTTP
  • structured email handling
  • reusable validation logic