Skip to main content

Posts

Showing posts from July, 2025

๐Ÿคฏ “Why Integer a = 128; Integer b = 128; Broke My Brain”

๐ŸŽฌ Intro — “I Thought I Knew ==… Until Java Proved Me Wrong” I was casually writing: Integer a = 128; Integer b = 128; System.out.println(a == b); // Output: false ❌ …and confidently told myself: “Yeah, that’s definitely true.” ๐Ÿ’ฅ WRONG! Output: false I was like… ๐Ÿง‍♂️ “Hello? Java, are you okay?” Let's break this down, and I’ll show you what I learned — in my usual style: with humor, diagrams, dumb-but-smart questions, and gotchas! ๐Ÿงช 1. Code Examples That Confused Me ✅ Primitive Comparison Works int a = 128; int b = 128; System.out.println(a == b); // true ✅ ➡️ Simple! Both values are 128, both stored in stack. Done. ❌ Object Comparison Fails? Integer a = 128; Integer b = 128; System.out.println(a == b); // false ❌ ➡️ Wait, same values, but still false? ✅ Mixed (Object + Primitive) Integer a = 128; int b = 128; System.out.println(a == b); // true ✅ ➡️ What? Now it works again?

๐Ÿ—“️ That Day I Learned Something Loggically Shocking! ๐Ÿคฏ๐Ÿ’ก Clue: A tiny "+" in your logger can silently become your app's performance enemy! ๐Ÿ›⚠️

๐Ÿ—“️  That Day I Learned Something Loggically Shocking! ๐Ÿคฏ Hey everyone! ๐Ÿ‘‹ So recently while working on my project, I stumbled upon something super basic — yet kinda blew my mind. ๐Ÿ’ฅ I wrote this: log.info("hi {}", 0); Then I asked myself... ๐Ÿค” "Why not just write this?" log.info("hi" + 0); I mean… both give me hi0, right? ๐Ÿงต️ What could possibly go wrong? Turns out — A LOT. Let me take you into this funny-yet-real rabbit hole ๐Ÿ•ณ️๐Ÿ‡ of how a tiny change in logging style can silently mess with your app’s performance — and how even your logs have trust issues! ๐Ÿ˜‚ ๐Ÿ” First of All — What is Log4j? Log4j (Logging for Java) is a popular logging library used to capture logs (debug, info, error, etc.) in your Java applications. It gives you control over: What gets logged (log level) Where it goes (console, file, DB) How it's formatted (pattern layout) And much more... It's basically your app's diary ๐Ÿ“œ — but wi...

๐Ÿ”ฅ Top 20 Java Coding Standards vs Anti-Patterns — With Real Examples & Fixes!

๐Ÿ”ฅ Top 20 Java Coding Standards vs Anti-Patterns — With Real Examples & Fixes! Welcome to a no-nonsense, funny, and deeply educational guide that’ll help you avoid bugs, write cleaner code, and ace interviews. Let’s roll! ๐ŸŽฏ ๐ŸŽฏ 1. Avoid Wildcard Imports (import.*) ✅ Best: import java.util.List; import java.util.ArrayList; ❌ Worst: import java.util.*; ๐Ÿ’ฅ What goes wrong: - Conflicting classes (like java.util.Date vs java.sql.Date) - IDE slows down due to unnecessary type loading - Harder for humans to read ๐Ÿ˜‚ "I use * because I believe in surprises!" — Future you debugging a Date conflict ⚡ 2. Fail Fast Design if (user == null) throw new IllegalArgumentException("User can't be null"); user.getName(); // Boom! NPE gift ๐ŸŽ ๐Ÿง  Catch bugs early, easier to debug. ๐Ÿ›ก️ 3. Immutable DTOs public record UserDTO(String name, int age) {} public class UserDTO { public String name; public int age; } ...

๐Ÿ’ฅ "Wait... Why Is It NULL?!?" — When @Value("${...}") Ignores Your Static Field ๐Ÿ˜ต‍๐Ÿ’ซ

๐Ÿ”  A surprising Spring Boot moment I didn't expect — and the rabbit hole it took me down... ๐ŸŽฌ It All Started With a Simple Idea... You know how it goes… You define a config value like this in application.properties : payment.currency=INR And then you boldly write this innocent-looking code: @Component public class PaymentUtil { @Value("${payment.currency}") private static String currency; // ✅ Logical! Right? public static void printCurrency() { System.out.println("Currency: " + currency); } } You run the app. And BAM ๐Ÿ’ฅ Currency: null ๐Ÿ˜ต "Eh? I clearly defined the property. Is it not reading the file? Do I need a restart? Do I need to yell at my laptop?" ๐Ÿคฏ The Shocking Discovery Spring doesn’t inject values into static fields. Yes, my friend. Even if you beg it with @Value . And trust me — it’s not a bug. It’s a feature. ๐Ÿ™ƒ ๐Ÿง  What Is This Dependency Injection (DI) Sorcery ...

๐Ÿšš Pass By Value vs Pass By Reference in Java — The Great Confusion Buster ๐Ÿ’ฃ

  ๐Ÿ’ฌ “I changed the object inside a method. But when I came back… NOTHING happened. Java, are you even listening to me?!” ๐Ÿ˜ก That was me. Screaming at my screen. So I decided to dig deep: What’s really going on? Let’s go from basics → to bugs → to JVM internals → to truth ๐Ÿ’ก ๐ŸŽฏ What People Think Java Does: public void change ( int x) { x = 10 ; } “Cool, this is pass-by-value. Just a copy. I get it.” ✅ But then... public void update (User u) { u.setName( "Anand" ); } “Wait, it changed outside! That must be pass-by-reference!” ❓ And then... public void update (User u) { u = new User ( "NewGuy" ); } “Now it DIDN’T change outside?!  Java, are you drunk?” ๐Ÿบ ๐Ÿง  Truth Bomb: Java is Always Pass-by-Value. No Exceptions. Even for objects. But here's the tricky twist: ๐Ÿ“Œ Java passes a copy of the reference when dealing with objects. So you're not passing the object directly — You're passing a copy of the point...

๐ŸฅŠ @Component vs @Configuration — Not Just Cousins in Spring! ๐Ÿ˜ฒ

 ๐Ÿง  Ever looked at these two annotations and thought: “Aren’t they doing the same thing ?” Welcome to the club. I had the same confusion until... I went deep down the Spring rabbit hole ๐Ÿ•ณ️๐Ÿ‡ Let’s clear this once and for all — with real differences , examples , gotchas , and even a few bad jokes along the way ๐Ÿ˜Ž ๐ŸŒŸ The Basic Definitions Annotation Meaning @Component A general-purpose stereotype indicating a class is a Spring-managed bean @Configuration A specialized class used to declare beans via @Bean methods ๐Ÿ’ก Both register beans with Spring — but what happens behind the scenes is where it gets spicy ๐ŸŒถ️ ๐Ÿค” But Aren’t They Both Just “Beans”? Short answer: Yes . Long answer: It’s complicated — like your last relationship ๐Ÿ’”. ⚙️ INTERNAL MAGIC: The Real Difference 1. @Con...

๐Ÿ’ก SOLID Principles: Why Interviewers Love Them & How They Can Make You a Better Developer!

Why is every microservices interview like a detective asking: ‘Do you know SOLID principles?’ ๐Ÿ˜ฉ Let’s be honest — lots of developers (especially freshers) get confused or forget them. Haha… even I was one of them! ๐Ÿ˜… And hey — I’m not the G.O.D (Guru Of Design) to remember everything every time! ๐Ÿคท‍♂️๐Ÿ˜‚ But once I started imagining LinkedIn’s real-life features — job posts, messaging, news feeds — SOLID became unforgettable ๐ŸŽฏ And now, it's stuck in my brain… just like that one annoying ad you can’t skip. ๐Ÿ˜œ What Are SOLID Principles? The five commandments of Object-Oriented Design, created by the software guru Robert C. Martin (Uncle Bob) . They help us write: ๐Ÿงผ Clean ๐Ÿ”ง Maintainable ๐Ÿ”„ Flexible ๐Ÿงฑ Extensible ๐Ÿ“ฆ Reusable code. ๐Ÿ”‘ Why SOLID Matters in Microservices Interviews? Because good code is like a good city — modular, scalable, maintainable . Interviewers ask this because: They want to know if you write code that grows well ๐ŸŒฑ If you design serv...