Category Archives: Java

Secure Your Jersey REST APIs – Complete Authentication & Authorization Guide

Exposing a REST endpoint is only half the job — you also need to control who can call it and what they are allowed to do. Jersey, the reference implementation of Jakarta RESTful Web Services (JAX-RS), provides a clean extension point through ContainerRequestFilter that lets you intercept every request before it reaches your resource class. In this guide you will implement HTTP Basic authentication, JWT Bearer-token validation, and role-based authorization step by step, using plain Jersey and then the Spring Boot integration.

Continue reading Secure Your Jersey REST APIs – Complete Authentication & Authorization Guide

Mastering Maven: How to Create Your Own Custom Archetypes

Every time you run mvn archetype:generate, Maven reads a blueprint called an archetype to scaffold your project structure. The built-in archetypes cover plain Java and simple web apps, but when your team has its own folder conventions, preferred dependencies, or boilerplate code, you need a custom archetype. In this guide you will build a complete custom Maven archetype from scratch, install it to your local repository, generate a new project from it, and optionally deploy it to a team-shared repository so your whole organisation can use it in one command.

Continue reading Mastering Maven: How to Create Your Own Custom Archetypes

Mastering Credit Card Validation with Regular Expressions in Java

Validating credit card numbers at the point of entry catches typos before an expensive payment gateway call is made. In this tutorial you will learn how to use Java regular expressions to check card number format for the major card networks, and then apply the Luhn algorithm — the checksum standard built into every valid card number — to confirm the number is mathematically plausible. The combination of regex format check + Luhn checksum is the industry-standard client-side validation used by checkout pages worldwide.

Continue reading Mastering Credit Card Validation with Regular Expressions in Java

A Practical Guide to Formatting ZonedDateTime in Java

ZonedDateTime is the most complete date-time class in the modern java.time API: it stores a date, a time, and a full timezone (e.g. America/New_York). Displaying it in a human-readable or machine-readable format requires the DateTimeFormatter class. In this tutorial you will learn every important formatting pattern, understand the difference between predefined ISO formatters and custom patterns, and see how to parse a string back into a ZonedDateTime — all with annotated code examples and sample output.

Continue reading A Practical Guide to Formatting ZonedDateTime in Java

JMS Deep Dive: A Practical Guide to Asynchronous Messaging in Java

The Java Message Service (JMS) API is the standard Java EE / Jakarta EE API for sending, receiving, and reading messages in an asynchronous, loosely coupled way. Rather than having Service A call Service B directly, JMS lets A drop a message onto a queue or topic and carry on. Service B picks it up whenever it is ready. In this guide you will learn the key JMS concepts, study both queue (point-to-point) and topic (publish-subscribe) messaging models, and walk through a fully working Java example using Apache ActiveMQ — the most widely deployed open-source JMS broker.

Continue reading JMS Deep Dive: A Practical Guide to Asynchronous Messaging in Java

Java Comparable vs Comparator: The Definitive Guide with Examples

Every Java developer eventually reaches for Collections.sort() or List.sort() and immediately faces a choice: implement Comparable on the class, or pass a Comparator at the call site? The two interfaces serve different purposes, and picking the wrong one leads to inflexible designs and subtle ordering bugs. In this guide you will understand exactly what each interface does, see annotated side-by-side examples, and learn the rules for when to use which — including the modern lambda and method-reference syntax that makes comparators a joy to write.

Continue reading Java Comparable vs Comparator: The Definitive Guide with Examples

Java BufferedReader Tutorial: Read Files and Console Input Efficiently

BufferedReader is the go-to class for reading text efficiently in Java. By wrapping any Reader in a buffer, it dramatically reduces the number of low-level I/O calls needed, making it orders of magnitude faster than reading one character at a time. In this tutorial you will learn how BufferedReader works under the hood, master every important method with annotated examples, and see the modern try-with-resources pattern that guarantees the stream is always closed properly.

Continue reading Java BufferedReader Tutorial: Read Files and Console Input Efficiently