Skip to main content

Java

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

A complete, from-scratch implementation of a feedforward neural network in pure Java — no TensorFlow, no DL4J, no external libraries. Covers the Neuron model, forward propagation, sigmoid activation, backpropagation with gradient descent, and trains the network to learn the XOR function. Every line of code is annotated with the underlying mathematics so you understand exactly what the network is doing at each step.

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

A complete beginner's guide to building a REST API with Spring Boot 3. Covers project setup, clean package structure, a Java record model with Bean Validation, a service layer, a @RestController with GET/POST/PUT/DELETE endpoints, global exception handling with @RestControllerAdvice, and end-to-end curl testing u2014 with fully annotated code throughout.

Java Collections Framework: Choosing the Right Data Structure

A complete, reference-level guide to the Java Collections Framework. Covers ArrayList vs LinkedList, HashSet vs LinkedHashSet vs TreeSet, HashMap vs LinkedHashMap vs TreeMap, PriorityQueue, ArrayDeque, and immutable collections u2014 with time-complexity tables, annotated code examples, and a decision guide for choosing the right data structure.

Java Streams API: The Complete Reference Guide

A complete, reference-level guide to the Java Streams API (Java 8+). Covers stream creation, intermediate operations (filter, map, flatMap, sorted, distinct, peek), terminal operations (collect, reduce, count, findAny, anyMatch), collectors, parallel streams, and the most common pitfalls u2014 with fully annotated code and sample output for every example.

A Developer’s Guide to Testing Spring REST Clients with @RestClientTest

In modern microservices architecture, it's rare for a service to live in complete isolation. Most applications need to communicate with other services over the network, typically via REST APIs. When you build a component that consumes an external REST API, a critical question arises: how do you test it reliably without actually making network calls to a live, and potentially unstable, external service? This is where Spring Boot's test slices come to the rescue. For testing your REST clients, the framework provides a powerful and elegant solution: the @RestClientTest annotation. Let's dive deep into how you can use it to write clean, fast, and reliable tests for your HTTP client components. What Exactly is @RestClientTest? @RestClientTest is a "test slice" annotation specifically designed to test REST client components. Instead of loading your entire Spring application context (like @SpringBootTest does), it focuses only on the beans relevant to REST client operations. This makes your tests significantly faster and less prone to side effects from unrelated configurations. When you use @RestClientTest, Spring Boot will auto-configure the following for you: The Client Under Test: The specific REST client bean you want to test. MockRestServiceServer: A bean that lets you mock the server-side responses. You can instruct it: "When my client calls /api/employees/1, respond with this specific JSON." RestTemplateBuilder: Used to help construct RestTemplate instances. Jackson/Gson Support: It automatically includes support for serializing and deserializing JSON, so you can test your client-side data mapping. In short, it provides the perfect, minimal environment to verify that your client builds the correct HTTP request and correctly parses the HTTP response — all without a single packet leaving your machine.

Dozer Bean Mapping in Java: Practical Guide with Benchmark vs MapStruct

Dozer is a battle-tested Java bean mapper that eliminates DTO-to-entity boilerplate using runtime reflection. This guide covers basic and nested mapping, custom converters, Spring integration, and a head-to-head benchmark vs MapStruct — so you can choose the right tool for your project.

Java HashMap vs ConcurrentHashMap: Complete Interview Guide

In Java collections framework, HashMap and ConcurrentHashMap are two of the most frequently discussed topics in technical interviews. While HashMap provides fast key-value storage for single-threaded environments, ConcurrentHashMap extends these capabilities to support concurrent access. This comprehensive guide covers essential interview questions about both data structures, their internal workings, and key differences. HashMap Fundamentals What is HashMap? HashMap is a hash table based implementation of the Map interface in Java. It stores key-value pairs and provides constant-time performance for basic operations like get() and put() assuming the hash function disperses elements properly. HashMap is part of the Java Collections Framework and resides in java.util package. How HashMap Works Internally The internal architecture of HashMap consists of an array of buckets where each bucket is a linked list (or tree in Java 8+) of entries. When you store a key-value pair, HashMap calculates the hash of the key to determine the bucket location. In Java 8+, when a bucket contains too many entries (default threshold is 8), it converts the linked list into a balanced red-black tree for faster lookups.

How to Check if a Number is a Pronic Number in Java

Whether you are preparing for a technical interview or exploring the fascinating world of number theory, encountering Pronic numbers is almost a rite of passage for Java developers. These numbers, often hidden in pattern-matching puzzles, have unique properties that make them a favorite for practicing algorithmic efficiency. In this guide, we will dive deep into what Pronic numbers are and demonstrate two distinct ways to identify them using Java—ranging from a beginner-friendly loop to a high-performance mathematical "trick." What is a Pronic Number? A Pronic number (also known as an oblong or rectangular number) is a number that is the product of two consecutive integers. Mathematically, a number P is pronic if it can be expressed as: P = n X (n + 1) For some integer n. Examples of Pronic Numbers: 0: 0 X 1 = 0 2: 1 X 2 = 2 6: 2 X 3 = 6 12: 3 X 4 = 12 20: 4 X 5 = 20

Log4j2 Logging Levels – Complete Guide

Imagine your application's log file as a constant stream of information. In a production crisis, this stream becomes a firehose. How do you find the single critical error message in a flood of routine status updates? The answer lies in logging levels. These aren't just labels; they are the fundamental control mechanism in Log4j2. They allow developers to filter noise, pinpoint failures, and monitor application health effectively. Mastering this hierarchy is the key to creating logs that are helpful, not overwhelming. This guide explores Log4j2’s levels, from configuration to real-world best practices. The Logging Threshold: How Levels Work Think of logging levels as a gatekeeper's volume knob. Each log message you write (an "event") is assigned a level of importance, or severity. The logger itself is then configured with a threshold level. When a message arrives, the framework compares its severity to the logger's threshold. Only messages at or above the configured threshold are processed and sent to their destination (like a file or the console). This simple mechanism provides fine-grained control over your application's verbosity. You can run the exact same code in different environments and get drastically different log outputs—all without changing a single line of Java. In development, you might set the threshold low to see everything. In production, you set it high to capture only significant errors.