Skip to main content

TypeScript Arithmetic Operators: The Definitive Guide

TypeScript didn’t reinvent JavaScript’s arithmetic — it just gave you a seatbelt. Under the hood, every +, -, *, /, and ** behaves exactly like in JavaScript, including all the quirky coercion rules that have launched a thousand memes. What TypeScript adds is the ability to catch those bugs at compile time instead of 3 a.m. when a user enters “banana” in a price field. This guide covers every arithmetic operator in TypeScript with modern, real-world examples, in-depth explanations, common pitfalls, performance notes, and a cheat-sheet you’ll actually use. 1. Unary Operators Unary Plus + Purpose: Explicitly converts its operand to a number using the same algorithm as Number() but much faster. +"42"; // 42 +"3.14"; // 3.14 +""; // 0 (empty string → 0) +" 123 "; // 123 (trims whitespace!) +"0xFF"; // 255 (recognizes hex) +"abc"; // NaN +true; // 1 +false; // 0 +null; // 0 +undefined; // NaN (compile error if strictNullChecks is on)

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.

Spring Security Context Propagation: The Complete Guide (With Virtual Threads & Structured Concurrency)

Spring Security's SecurityContext is the cornerstone of authentication and authorization in Spring applications, but propagating it across thread boundaries is a real trap in async, reactive, and now virtual-thread code. This guide covers ThreadLocal strategies, servlet and WebFlux propagation, @Async/ExecutorService/CompletableFuture, and—updated for Boot 4.1—virtual threads, DelegatingSecurityContextExecutor, ContextPropagatingTaskDecorator, and StructuredTaskScope, each verified against real, captured output.

8086 Assembly Program to Compute Factorial of an Integer Using Recursion

This blog post will dive into a more advanced concept in 8086 assembly: computing the factorial of a number using recursion. Unlike iterative approaches using loops, recursion involves a procedure calling itself. This example highlights crucial concepts of stack management (PUSH and POP), procedure calls (CALL and RET), and conditional jumping to handle base cases. Let’s explore how the stack handles the "memory" of recursive calls! ; Program to calculate Factorial of a number using Recursion ; Input: num (e.g., 5) ; Output: result (e.g., 5! = 120 or 78h) data segment num dw 0005h ; The number to calculate factorial for (16-bit word) result dw ? ; Variable to store the final 16-bit result data ends code segment assume cs:code, ds:data start: mov ax, data mov ds, ax ; Initialize Data Segment mov cx, num ; Load the input number into CX register used as counter/argument mov ax, 0001h ; Initialize accumulator AX to 1 (needed for multiplication) call factorial ; Call the recursive procedure mov result, ax ; Store final result from AX into memory variable int 3 ; Breakpoint to halt and check registers ;--- Recursive Procedure Definition --- factorial proc near cmp cx, 1 ; BASE CASE: Check if number in CX is <= 1 jbe base_case ; If CX is 0 or 1, jump to base_case to return push cx ; RECURSIVE STEP: Save current state of CX on STACK dec cx ; Decrement CX to move towards base case (N-1) call factorial ; Recursive Call: factorial(N-1) pop cx ; UNWINDING: Restore the saved value of CX from STACK mul cx ; AX = AX * CX. (Current Result * Current N) ret ; Return to caller base_case: mov ax, 1 ; Base case returns 1 (as 0! = 1 and 1! = 1) ret ; Return to caller factorial endp ;-------------------------------------- code ends end start

Master Custom Authentication Providers in Spring Security 7.1

A from-scratch guide to writing a custom AuthenticationProvider in Spring Security 7.1 (Spring Boot 4.1): what actually wires an AuthenticationProvider bean into the AuthenticationManager, why the old manual ProviderManager pattern was never necessary, and how to run a custom provider alongside a JWT-secured API in the same application without the two colliding.

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

Complete Guide to Enabling HTTPS on Apache Tomcat

When your web application moves beyond hobby status, the first hardening step is wrapping every byte in TLS. Tomcat makes the process painless once you understand where the moving parts live. In this guide you will create (or import) a certificate, wire it into Tomcat’s connector, and verify that the padlock appears in every browser. Why HTTPS on Tomcat Matters Plain HTTP exposes cookies, credentials, and payloads to anyone on the wire. Search engines penalize insecure sites, browsers now flag non-TLS pages as “Not Secure”, and compliance frameworks such as PCI-DSS simply forbid clear-text traffic. Turning on HTTPS: Encrypts data in transit Proves server identity to clients Unlocks HTTP/2 and modern protocols Keeps Google and your security team happy Prerequisites and Environment Before touching configuration files ensure: Tomcat 9.x or 10.x is installed and starts cleanly on port 8080 JAVA_HOME points to JDK 8+ (keytool comes with the JDK) OpenSSL 1.1+ if you prefer generating private keys externally Server DNS name (e.g. app.ankurm.com) resolves to the VM or container

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.

Understanding JUnit 5 @AfterEach Annotation with Practical Examples

In the world of Java development, writing a test is only half the battle. The real challenge lies in ensuring those tests are isolated, repeatable, and clean. If your first test leaves a database connection open, a locked file in the filesystem, or a messy entry in a shared cache, your second test might fail—not because of a bug in your production code, but because of a "dirty" environment. These "flaky tests" are the bane of modern CI/CD pipelines, leading to wasted developer time and decreased confidence in the build. This is where the JUnit 5 @AfterEach annotation becomes your best friend. In this comprehensive guide, we will dive deep into how to use this lifecycle callback to manage resource cleanup, maintain test integrity, and ensure that every test runs in a pristine environment. What is @AfterEach? The @AfterEach annotation marks a method that should be executed after every individual @Test method in the current class. Think of it as the "janitor" of your testing suite; no matter if your test passes, fails, or throws an unexpected exception, the @AfterEach method steps in to sweep the floor and reset the stage for the next performer. Unlike its counterpart @AfterAll (which runs once after the entire class is finished), @AfterEach is granular. It ensures that the state is reset immediately after each logic check, preventing "leakage" where the side effects of Test A interfere with the assertions of Test B.