Tag Archives: 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

Complete Guide to Logback RollingFileAppender

Without log rotation, a long-running Java application will eventually fill your disk with a single ever-growing log file. Logback’s RollingFileAppender solves this by automatically creating a new log file when a threshold is crossed and optionally compressing or deleting old files. In this guide you will learn every rolling policy Logback provides, understand each configuration attribute, and walk away with production-ready logback.xml examples you can drop into your Spring Boot or plain Java application today.

Continue reading Complete Guide to Logback RollingFileAppender

Masking Sensitive Data in Logback: A Complete Developer Guide

Logging is indispensable for debugging and observability — but logs that accidentally capture credit card numbers, passwords, or Social Security Numbers can turn a routine audit into a data-breach incident. In this guide you will learn three practical techniques for masking sensitive data in Logback: a zero-code XML replacement rule, a lightweight custom MessageConverter, and a full PatternLayout override. Every approach comes with working code, a comparison table, and production-hardening tips.

Continue reading Masking Sensitive Data in Logback: A Complete Developer Guide

Implementing Vector Embeddings and Semantic Search in Pure Java

Every modern AI search system — from Google to ChatGPT’s retrieval pipeline — works by converting text into numerical vectors and measuring how close those vectors are in high-dimensional space. This technique is called semantic search, and the numerical representations are called vector embeddings. Despite being the backbone of Retrieval-Augmented Generation (RAG), recommendation engines, and intelligent search, virtually every tutorial on the internet implements it in Python. Java developers are left guessing.

This post builds a complete semantic search engine in pure Java — no LangChain4j, no Spring AI, no external dependencies. We implement TF-IDF vectorisation, cosine similarity, and a query engine that ranks documents by meaning rather than keyword matching. By the end, you will understand the exact mathematics that powers every vector database on the market.

Continue reading Implementing Vector Embeddings and Semantic Search in Pure Java

Building a Neural Network from Scratch in Pure Java (No Libraries)

Neural networks power everything from image recognition to language models, yet most tutorials use Python and hide the mathematics behind library calls. If you are a Java developer, building a neural network from raw arithmetic — no TensorFlow, no DL4J, no dependencies at all — is the single best way to internalise how learning actually works at the weight-and-gradient level.

This post implements a fully connected, multi-layer feedforward neural network in pure Java. The network learns the XOR function, a classic problem that a single-layer perceptron cannot solve, which is exactly why it is the standard benchmark for testing that backpropagation is implemented correctly. Every line is annotated with the mathematics driving it.

Continue reading Building a Neural Network from Scratch in Pure Java (No Libraries)

Building a REST API with Spring Boot: Complete Beginner's Guide

Spring Boot strips away the configuration ceremony that used to make Spring applications time-consuming to set up. You add a dependency, annotate a class, and a production-grade REST endpoint is running in seconds. This guide builds a complete, working REST API from a blank project to a tested, structured service – explaining every decision along the way.

By the end you will have a runnable Spring Boot application with GET, POST, PUT, and DELETE endpoints, proper HTTP status codes, global exception handling, validation, and a structure that scales to a real project.

Continue reading Building a REST API with Spring Boot: Complete Beginner's Guide