<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: levi</title>
    <description>The latest articles on DEV Community by levi (@levii07).</description>
    <link>https://dev.to/levii07</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1233854%2F5398e545-9b8e-48e1-8ad6-4a2eed173128.webp</url>
      <title>DEV Community: levi</title>
      <link>https://dev.to/levii07</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/levii07"/>
    <language>en</language>
    <item>
      <title>How DNS works? : The Indian Post office analogy</title>
      <dc:creator>levi</dc:creator>
      <pubDate>Wed, 20 Aug 2025 18:07:13 +0000</pubDate>
      <link>https://dev.to/levii07/how-dns-works-the-indian-post-office-analogy-3mn2</link>
      <guid>https://dev.to/levii07/how-dns-works-the-indian-post-office-analogy-3mn2</guid>
      <description>&lt;p&gt;Have you ever wondered how your browser knows where to find &lt;a href="http://www.dev.to"&gt;www.dev.to&lt;/a&gt;?&lt;br&gt;
Its all thanks to DNS (Domain Name System) — the phonebook or postal system of the internet.&lt;br&gt;
Let me break it down using something we all understand in India — the PIN code system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw5q0fn2fmfrrzsjnf0pl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw5q0fn2fmfrrzsjnf0pl.png" alt="POST MAN FINDNG HOME ADDRESS" width="500" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine you want to send a letter to "&lt;a href="http://www.dev.to"&gt;www.dev.to&lt;/a&gt;"&lt;br&gt;
But you don’t know the exact house (IP address), only the name.&lt;br&gt;
Here's how the process unfolds:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Root DNS Server = Central Postal Director 
This is like India’s central postal directory.
It doesn’t know where dev.to lives, but it knows:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;"For .to domains, talk to the .to postal hub."&lt;/p&gt;

&lt;p&gt;Just like the central system knows:&lt;br&gt;
"For PINs starting with 1, go to Delhi. For 5, go to Hyderabad."&lt;br&gt;
but dyk, there are onnly 13 such root servers.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;TLD Server = Regional Postal Hub (like .to Office) &lt;br&gt;
The .to server is like the regional hub for .to addresses.&lt;br&gt;
It says:&lt;br&gt;
"I know who handles dev.to. Go talk to that local post office (authoritative server)."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Authoritative DNS Server = Local Post Office &lt;br&gt;
Now you're at the final post office — they know the exact house address:&lt;br&gt;
And this is where like of AWS route 53 comes in picture, responds to DNS queries for your domain, telling users where to find your website or app.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;"&lt;a href="http://www.dev.to"&gt;www.dev.to&lt;/a&gt; lives at 192.0.2.1". &lt;/p&gt;

&lt;p&gt;That’s the IP your browser needs to load the site.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe48277xrpg38bmyegpuj.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe48277xrpg38bmyegpuj.webp" alt="DNS WOrking" width="800" height="938"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>explainlikeimfive</category>
      <category>dns</category>
      <category>learning</category>
      <category>networking</category>
    </item>
    <item>
      <title>Day-7: InstanceOf and access modifiers: JAVA</title>
      <dc:creator>levi</dc:creator>
      <pubDate>Tue, 12 Aug 2025 16:25:59 +0000</pubDate>
      <link>https://dev.to/levii07/instanceof-java-b0a</link>
      <guid>https://dev.to/levii07/instanceof-java-b0a</guid>
      <description>&lt;h2&gt;
  
  
  🔍 What is &lt;code&gt;instanceof&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;instanceof&lt;/code&gt; operator checks &lt;strong&gt;whether an object is an instance of a specific class, subclass, or interface&lt;/strong&gt;. It returns a boolean result.&lt;/p&gt;




&lt;h2&gt;
  
  
  📘 Summary of Key Concepts
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Type Check&lt;/strong&gt;: Checks if an object is of a given type.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Returns Boolean&lt;/strong&gt;: Returns &lt;code&gt;true&lt;/code&gt; if the object is of the specified type or a subtype.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interfaces&lt;/strong&gt;: Works with interfaces and superinterfaces.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Object Type Matters&lt;/strong&gt;: Evaluates based on the actual object, not the declared variable type.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Superclass Match&lt;/strong&gt;: Returns &lt;code&gt;true&lt;/code&gt; if object is an instance of a superclass in the hierarchy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Null Always False&lt;/strong&gt;: &lt;code&gt;instanceof&lt;/code&gt; always returns &lt;code&gt;false&lt;/code&gt; when the object is &lt;code&gt;null&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compile-Time Safety&lt;/strong&gt;: If the compiler knows the check is impossible (e.g., &lt;code&gt;String instanceof Integer&lt;/code&gt;), it gives a compile error.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Safe Downcasting&lt;/strong&gt;: Often used to check type before downcasting to avoid &lt;code&gt;ClassCastException&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pattern Matching&lt;/strong&gt;: Allows type check and casting in one step:
&lt;code&gt;
if (obj instanceof String s) {
   System.out.println(s.toUpperCase());
}&lt;/code&gt;
10.&lt;strong&gt;Short-Circuit Logic&lt;/strong&gt;: Pattern variable can be used in same condition safely:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (obj instanceof String s &amp;amp;&amp;amp; s.length() &amp;gt; 5) {
    System.out.println(s);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;TRICKY QUESTION&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;whats null instanceof null?
Compile time error.instanceof requires the right-hand side to be a class or interface type.:&lt;/li&gt;
&lt;li&gt;Can we check enum instanceof?
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum Color { RED, GREEN }
Color c = Color.RED;
System.out.println(c instanceof Color);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes,enums are classes and extend java.lang.Enum, so instanceof works with them.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;whats int instanceof Integer?
Compile-time error,instanceof cannot be used with primitives.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  ACCESS MODIFIER:
&lt;/h3&gt;

&lt;p&gt;Java provide 4 types of access modifiers, class/field/method defined as:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;private&lt;/strong&gt;: can only be accessed within same class not even in the subclasses. denoted by **private **keyword.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;package-private&lt;/strong&gt;: denoted by no keyword. this give visibility of entity through out same package.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;protected&lt;/strong&gt; : similar to package-private but its subclasses can also access protected entities. use **protected **keyword&lt;/li&gt;
&lt;li&gt;public: can be accessed everywhere. use **public **keyword.&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Day 6- Switch Smarter in Java 21</title>
      <dc:creator>levi</dc:creator>
      <pubDate>Mon, 11 Aug 2025 17:27:27 +0000</pubDate>
      <link>https://dev.to/levii07/switch-smarter-in-java-21--kae</link>
      <guid>https://dev.to/levii07/switch-smarter-in-java-21--kae</guid>
      <description>&lt;p&gt;Day 6: Learnt About Modern switch in Java 21&lt;/p&gt;

&lt;h2&gt;
  
  
  Goodbye Break, Hello -&amp;gt;
&lt;/h2&gt;

&lt;p&gt;Modern switch in Java 21 allows using arrow syntax (-&amp;gt;), so you can skip the break keyword and avoid accidental fall-throughs.&lt;/p&gt;

&lt;p&gt;Without arrow syntax, you can use the yield keyword to return a value from a switch expression.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To group multiple case values, use a comma-separated list:
&lt;code&gt;case 1,2 -&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;When using a sealed hierarchy, the compiler checks for exhaustiveness at compile time:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sealed interface Shape permits Circle, Square {}
final class Circle implements Shape {}
final class Square implements Shape {}

String result = switch (shape) {
    case Circle c -&amp;gt; "Circle!";
    case Square s -&amp;gt; "Square!";
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;it also supports null case unlike classic java. &lt;br&gt;
&lt;code&gt;case null-&amp;gt;"no"&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It supports pattern matching and guards (when), allowing type checks and additional conditions directly in switch:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Object obj = 10;

String result = switch (obj) {
    case Integer i when i &amp;gt; 5 -&amp;gt; "Large number";
    case Integer i -&amp;gt; "Small number";
    default -&amp;gt; "Other";
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>dailylog</category>
      <category>100daysofcode</category>
      <category>learning</category>
    </item>
    <item>
      <title>JUST STATIC it: Understanding static in Java</title>
      <dc:creator>levi</dc:creator>
      <pubDate>Thu, 07 Aug 2025 17:45:55 +0000</pubDate>
      <link>https://dev.to/levii07/just-static-it-everthing-about-static-keyword-1eki</link>
      <guid>https://dev.to/levii07/just-static-it-everthing-about-static-keyword-1eki</guid>
      <description>&lt;p&gt;DAY 5. I am trying to strength by Core java basic its one of the concepts I struggle to understand. here is everthing I learnt today about static keyword in java &lt;/p&gt;

&lt;h2&gt;
  
  
  Java Summary: Static, Class Loading &amp;amp; Execution Flow
&lt;/h2&gt;




&lt;h2&gt;
  
  
  1. &lt;code&gt;static&lt;/code&gt; Keyword in Java
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The &lt;code&gt;static&lt;/code&gt; keyword means the member belongs to the class itself, not to instances.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CarFactory {
    // Static variable shared by all cars made by any factory
    static int totalCarsProduced = 0;

    // Static block: runs once when the class is loaded
    static {
        System.out.println("CarFactory class loaded. Initializing factory...");
    }

    // Instance variable (per car)
    String model;

    // Constructor increments total cars produced
    CarFactory(String model) {
        this.model = model;
        totalCarsProduced++;
    }

    // Static method: calculates price without needing an object
    static int calculatePrice(String model, int basePrice) {
        if ("Luxury".equalsIgnoreCase(model)) {
            return basePrice + 7000;
        } else {
            return basePrice;
        }
    }

    // Static nested class representing a part of the car
    static class Engine {
        void start() {
            System.out.println("Engine started.");
        }
    }
}

public class Main {
    public static void main(String[] args) {
        // Class loaded, static block runs first

        // Create cars (instances)
        CarFactory car1 = new CarFactory("Standard");
        CarFactory car2 = new CarFactory("Luxury");

        // Access static variable shared by all cars
        System.out.println("Total cars produced: " + CarFactory.totalCarsProduced); // 2

        // Call static method without creating an object
        int price = CarFactory.calculatePrice("Luxury", 25000);
        System.out.println("Price of Luxury car: $" + price);  // 32000

        // Create and use static nested class (no CarFactory instance needed)
        CarFactory.Engine engine = new CarFactory.Engine();
        engine.start();
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Where &lt;code&gt;static&lt;/code&gt; Can Be Used:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Static variable&lt;/strong&gt; → Shared among all instances (1 copy in memory)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Static method&lt;/strong&gt; → Can be called without object creation; can't access instance members directly
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Static block&lt;/strong&gt; → Runs once when class is loaded; used to initialize static fields. they cant return anything.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Static nested class&lt;/strong&gt; → Class inside another class; does NOT need outer class object
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Static Nested Class vs Inner Class
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Static Nested Class&lt;/th&gt;
&lt;th&gt;Inner (Non-Static) Class&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Access only static members of outer class&lt;/td&gt;
&lt;td&gt;Can access all members of outer class&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Does NOT require outer class instance&lt;/td&gt;
&lt;td&gt;Requires outer class instance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Can be instantiated independently&lt;/td&gt;
&lt;td&gt;Must be tied to an outer class object&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Key Rules:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Static methods can't access instance fields or methods directly.
&lt;/li&gt;
&lt;li&gt;Static methods can't be abstract.
&lt;/li&gt;
&lt;li&gt;Static methods can't be overridden (they're hidden instead).
&lt;/li&gt;
&lt;li&gt;Static blocks and variables execute &lt;strong&gt;in order of appearance&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. Class Loading &amp;amp; Initialization
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What Is Class Loading?
&lt;/h3&gt;

&lt;p&gt;Class loading is the process of bringing &lt;code&gt;.class&lt;/code&gt; files into memory using a &lt;strong&gt;ClassLoader&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Class Loaders:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Bootstrap ClassLoader – loads core Java classes (e.g., &lt;code&gt;java.lang&lt;/code&gt;)
&lt;/li&gt;
&lt;li&gt;Extension ClassLoader – loads JDK extensions
&lt;/li&gt;
&lt;li&gt;Application ClassLoader – loads user-defined classes
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  What Gets Loaded:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Class structure (fields, methods, hierarchy)
&lt;/li&gt;
&lt;li&gt;Constant pool
&lt;/li&gt;
&lt;li&gt;Static fields (with default values first)
&lt;/li&gt;
&lt;li&gt;Method bytecode
&lt;/li&gt;
&lt;li&gt;Static blocks
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Phases of Class Loading:
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Phase&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Loading&lt;/td&gt;
&lt;td&gt;Reads &lt;code&gt;.class&lt;/code&gt; file into memory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Linking&lt;/td&gt;
&lt;td&gt;Verifies bytecode, allocates memory for statics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Initialization&lt;/td&gt;
&lt;td&gt;Assigns actual static values, runs static blocks&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  3. JVM Memory Areas
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Memory Area&lt;/th&gt;
&lt;th&gt;What it Stores&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Method Area&lt;/td&gt;
&lt;td&gt;Class metadata, static variables, constant pool&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Heap&lt;/td&gt;
&lt;td&gt;Objects and instance variables&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stack&lt;/td&gt;
&lt;td&gt;Method calls and local variables (per thread)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PC Register&lt;/td&gt;
&lt;td&gt;Instruction pointer per thread&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Native Method Stack&lt;/td&gt;
&lt;td&gt;Native (non-Java) method calls&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  4. Java Program Execution Flow
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Steps When Running a Program
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Class is loaded&lt;/li&gt;
&lt;li&gt;Static variables are initialized&lt;/li&gt;
&lt;li&gt;Static blocks execute (in order)&lt;/li&gt;
&lt;li&gt;main() method is called&lt;/li&gt;
&lt;li&gt;If object is created:

&lt;ul&gt;
&lt;li&gt;Instance variables init&lt;/li&gt;
&lt;li&gt;Instance block runs&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Constructor runs&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  5. Final vs Static
&lt;/h3&gt;

&lt;p&gt;we will cover &lt;code&gt;final&lt;/code&gt; in depth another article.&lt;br&gt;
any member declared as:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;&lt;code&gt;static&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;final&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Belongs to&lt;/td&gt;
&lt;td&gt;Class&lt;/td&gt;
&lt;td&gt;Class or instance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Overriding&lt;/td&gt;
&lt;td&gt;Static methods &lt;strong&gt;cannot be overridden&lt;/strong&gt; (hidden)&lt;/td&gt;
&lt;td&gt;Final methods &lt;strong&gt;cannot be overridden&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inheritance&lt;/td&gt;
&lt;td&gt;N/A (related to members)&lt;/td&gt;
&lt;td&gt;Final class &lt;strong&gt;cannot be extended&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Usage&lt;/td&gt;
&lt;td&gt;Share common data, utility methods, nested classes&lt;/td&gt;
&lt;td&gt;Prevent modification of method/class inheritance&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  6. Where You Cannot Use static in Java?
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Usage&lt;/th&gt;
&lt;th&gt;Can you use &lt;code&gt;static&lt;/code&gt; here?&lt;/th&gt;
&lt;th&gt;Reason&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Local variables inside methods&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;Java does &lt;strong&gt;not&lt;/strong&gt; allow &lt;code&gt;static&lt;/code&gt; local variables&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Constructors&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;Constructors are always instance-level&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Abstract methods&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;static&lt;/code&gt; and &lt;code&gt;abstract&lt;/code&gt; are contradictory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Interfaces (before Java 8)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;But Java 8+ allows static &lt;strong&gt;methods&lt;/strong&gt; inside interfaces&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>learning</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Bulletproof Your APIs with Contract Testing</title>
      <dc:creator>levi</dc:creator>
      <pubDate>Sun, 15 Jun 2025 18:48:57 +0000</pubDate>
      <link>https://dev.to/levii07/bulletproof-your-apis-with-contract-testing-gaa</link>
      <guid>https://dev.to/levii07/bulletproof-your-apis-with-contract-testing-gaa</guid>
      <description>&lt;p&gt;&lt;strong&gt;🔍 Real-World Wake-Up Call&lt;/strong&gt;&lt;br&gt;
Once upon a time at work 😜, I was working on a project that heavily relied on multiple upstream services owned by different teams to process order data. One seemingly ordinary day, one of those services made a change to their API — they updated the productDescription field from a String to a List.&lt;/p&gt;

&lt;p&gt;Our service, still expecting a String, started throwing 400 Bad Request errors out of nowhere. This seemingly small change caused unexpected failures and impacted our downstream processing.&lt;/p&gt;

&lt;p&gt;This incident made it painfully clear: we needed a better way to catch breaking changes in API contracts early, before they hit production. That’s when we started exploring Contract Testing as a solution. Among the tools we considered were Spring Cloud Contract and Pact.&lt;br&gt;
Here url for POC we created:&lt;a href="https://dev.toContract%20Testing%20POC"&gt; https://github.com/levi-a07/contract-testing&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Spring Cloud Contract is a testing framework that helps ensure reliable communication between microservices by using contract testing&lt;br&gt;
A contract is a written agreement (in code) that defines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What the producer (API provider) promises to return, based on what the consumer (API client) sends.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Spring Cloud Contract allows you to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write these contracts (in Groovy/YAML),&lt;/li&gt;
&lt;li&gt;Automatically generate tests for the producer,&lt;/li&gt;
&lt;li&gt;Automatically generate mock stubs for the consumer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sample looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;description: Should return order by id
request:
  method: GET
  url: /orders/1
response:
  status: 200
  headers:
    Content-Type: application/json
  body:
    orderId: "1"
    productId: "product-1234"
    quantity: 2
    price: 29.99
  matchers:
    body:
      - path: $.orderId
        type: by_regex
        value: "\\d+"   # Matches any numeric orderId
      - path: $.productId
        type: by_regex
        value: "product-\\d+"  # Matches a product ID like product-123
      - path: $.quantity
        type: by_type
        value: number       # Matches any numeric quantity
      - path: $.price
        type: by_type
        value: number       # Matches any numeric price
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Types of Contract Testing
&lt;/h2&gt;

&lt;p&gt;There are 3 type of contracts:&lt;br&gt;
&lt;strong&gt;1. Consumer-Driven Contracts (CDC)&lt;/strong&gt;&lt;br&gt;
The contract is usually written from the consumer’s point of view, describing what it expects from the producer. The consumer service then uses a stub — an auto-generated mock server based on the contract — to simulate the producer’s behavior during testing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This stub reflects the contract exactly&lt;/strong&gt;, not the actual producer code. The consumer team can share the contract via a pull request to the producer repo or through a shared location. If the producer later changes the contract, the stub updates accordingly, and any mismatch will cause the &lt;strong&gt;consumer's test to fail&lt;/strong&gt;, alerting the team to the breaking change early.&lt;/p&gt;

&lt;p&gt;Based on the contract, Automatic Junit tests are created on Producer side. &lt;br&gt;
The generated tests simulate requests described in the contract and verify that the producer's real implementation returns the expected response. This way we catch breaking changes early.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Best for *&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Systems with multiple consumers and independent teams.&lt;/li&gt;
&lt;li&gt;Ensuring backward compatibility.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tool&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spring cloud contract&lt;/li&gt;
&lt;li&gt;Pact&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Producer-Driven Contracts **&lt;br&gt;
The producer defines the contract — the API specification — and shares it with consumers.&lt;br&gt;
**How it works:&lt;/strong&gt;&lt;br&gt;
Producer publishes the OpenAPI/Swagger schema or a written contract.&lt;br&gt;
Consumers build against this contract.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best for&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Where contracts are mostly controlled by producer service.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tools&lt;/strong&gt;&lt;br&gt;
OpenAPI/Swagger&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;3. Bidirectional Contracts&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A combination of consumer and producer contracts — both sides define expectations, and they are reconciled in a central place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Where contracts evolve from both sides.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tools&lt;/strong&gt;&lt;br&gt;
PactFlow&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br&gt;
In a microservices architecture, communication contracts between services are critical — yet easy to break. By automating contract validation, generating stubs, and catching breaking changes early in the pipeline, contract testing boosts confidence, improves collaboration across teams, and helps deliver more reliable systems.&lt;br&gt;
In the market we have different tools to use contracts based on your use case.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The Geometry Behind QR Codes: Exploring Matrix Rotation</title>
      <dc:creator>levi</dc:creator>
      <pubDate>Fri, 06 Jun 2025 15:03:34 +0000</pubDate>
      <link>https://dev.to/levii07/what-does-an-interviewer-want-to-test-with-the-rotate-image-problem-25fo</link>
      <guid>https://dev.to/levii07/what-does-an-interviewer-want-to-test-with-the-rotate-image-problem-25fo</guid>
      <description>&lt;p&gt;While practicing algorithm problems on LeetCode, I encountered the “Rotate Image” challenge. The problem is straightforward at first glance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Given an n x n matrix, rotate it 90 degrees clockwise in-place — without allocating any additional matrix.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I started solving it as a pure coding exercise, focusing on swapping elements layer by layer or using the transpose-and-reverse trick. But then I wondered: Why does this matter beyond interviews? Where is this matrix rotation used in the real world?&lt;br&gt;
At first glance, rotating an n x n matrix 90 degrees in-place might seem like just an exercise in array manipulation. &lt;/p&gt;

&lt;p&gt;But here’s a twist: Matrix rotation isn’t just an abstract puzzle. It’s a fundamental operation used in real-world technologies — like QR code scanning!&lt;br&gt;
Ever wondered how QR Codes store a phone number?&lt;br&gt;
When you encode a phone number (or any data) into a QR code, it’s transformed into a pattern of black and white squares, called modules. Each module encodes a bit of information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Black modules: Represent a 1&lt;/li&gt;
&lt;li&gt;White modules: Represent a 0&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As the amount of data increases, the QR code size (called the version) also grows. The smallest, version 1, is a 21x21 grid of modules, increasing in size for more complex data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How does the QR code guide the scanner?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fra6pskg325qyrq5rmtlf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fra6pskg325qyrq5rmtlf.png" alt="Image description" width="648" height="463"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;QR codes are clever. They contain specific patterns that help scanners locate, orient, and read the encoded data reliably—even if the QR code is tilted or partially distorted:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Finder Patterns:&lt;/strong&gt; Three large squares at the top-left, top-right, and bottom-left corners. These help the scanner detect the QR code’s position and rotation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Timing Patterns:&lt;/strong&gt; A sequence of alternating black and white modules along the horizontal and vertical axes that help determine the grid structure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Alignment Patterns:&lt;/strong&gt; Smaller squares scattered through larger versions of QR codes that correct for distortions like curvature or perspective changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quiet Zone:&lt;/strong&gt; The blank margin around the QR code separating it from surrounding text or images so scanners can distinguish the code boundaries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;So, where does matrix rotation come in?&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Imagine you scan a QR code tilted at an angle. Before decoding, the scanner must rotate the matrix of black and white modules to the correct orientation. This rotation is very much like the "Rotate Image" problem:&lt;/p&gt;

&lt;p&gt;The scanner needs to transform the 2D array in-place to correct the orientation — often rotating it 90, 180, or 270 degrees.&lt;/p&gt;

&lt;p&gt;This operation is critical for reliable decoding. Without it, the scanner might read the wrong bits or fail to find the finder patterns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In essence:&lt;/strong&gt;&lt;br&gt;
Matrix Rotation may not fully power QR code scanning but it definitely is first step.The scanning process typically follows this order: Skew &lt;strong&gt;Correction → Rotation → Perspective Correction&lt;/strong&gt;. Each step ensures that the QR code is properly aligned and readable, regardless of how it's captured.&lt;/p&gt;

</description>
      <category>explainlikeimfive</category>
      <category>programming</category>
      <category>learning</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How Joins work?</title>
      <dc:creator>levi</dc:creator>
      <pubDate>Mon, 02 Jun 2025 16:02:15 +0000</pubDate>
      <link>https://dev.to/levii07/how-joins-work-4c2k</link>
      <guid>https://dev.to/levii07/how-joins-work-4c2k</guid>
      <description>&lt;p&gt;Joins are like set operations.&lt;/p&gt;

&lt;p&gt;I know math can be intimidating, but this part isn’t that scary.&lt;/p&gt;

&lt;p&gt;INNER JOIN : get rows common to both table, matching key( primary and foreign key)&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;customer_id&lt;/th&gt;
&lt;th&gt;product&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Book&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Laptop&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT c.name, o.product
FROM customers c
JOIN orders o ON c.id = o.customer_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;output :&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;product&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;Book&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;Laptop&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;On&lt;/code&gt; clause specifies matching condition.&lt;/p&gt;

&lt;p&gt;Intuition:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Identify the table join:  Custumors and Orders&lt;/li&gt;
&lt;li&gt;we compare each row of table 1 with table 2 and look for the matching condition&lt;/li&gt;
&lt;li&gt;for every matching pair database combines the table columns&lt;/li&gt;
&lt;li&gt;If it's an INNER JOIN, only matched pairs are included.&lt;/li&gt;
&lt;li&gt;If it's a LEFT JOIN, all rows from the left table are included; if no match is found in the right table, NULLs fill the right side.&lt;/li&gt;
&lt;li&gt;For other join types, the logic changes slightly (like including unmatched rows on either side).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For obvious reasons, databases don't compare every row with every other row blindly.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔍 What Happens Under the Hood During a Join
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Cost Estimation&lt;/strong&gt; – The database estimates the CPU, memory, and I/O cost of different join strategies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Join Reordering&lt;/strong&gt; – It may reorder joins to start with the most selective table.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bloom Filters&lt;/strong&gt; – In some systems, these help reduce unnecessary data scanning.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  What are strategies Db uses for Joins?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Nested Loop Join: for each row in outer table, the database searches for matching rows in inner table. &lt;br&gt;
Con: can be very slow on large datasets.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hash Joins: db creates hash table(usually smaller one) on the key used for join. and then we lookup other table key in hash table.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;pro: No index required.&lt;br&gt;
con: uses extra memory for hashtable&lt;/p&gt;

&lt;p&gt;Drum roll .... &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Merge-join:
A merge join scans two sorted tables in order, comparing rows based on the join key.
When keys match, it returns the joined rows, moving pointers forward to continue merging efficiently.
example:&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;sale_id&lt;/th&gt;
&lt;th&gt;store_id&lt;/th&gt;
&lt;th&gt;amount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;300&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;250&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;Store A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;Store B&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;Store C&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Start at the first row of sales (store_id = 100) and the first row of stores (id = 100).&lt;/li&gt;
&lt;li&gt;Compare them:&lt;/li&gt;
&lt;li&gt;100 = 100 → MATCH → return this joined row: sale_id=1, store_id=100, amount=200, name=Store A&lt;/li&gt;
&lt;li&gt;Move both pointers forward.&lt;/li&gt;
&lt;li&gt;101 = 101 → MATCH → return: sale_id=2, store_id=101, amount=300, name=Store B&lt;/li&gt;
&lt;li&gt;Next: 102 = 102 → MATCH → return: sale_id=3, store_id=102, amount=250, name=Store C&lt;/li&gt;
&lt;li&gt;Efficient, fast, and only one scan through each table.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ✅ In Summary:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Joins combine tables by matching rows based on keys.&lt;/li&gt;
&lt;li&gt;INNER JOIN returns only matching rows.&lt;/li&gt;
&lt;li&gt;Different strategies (nested loop, hash, merge) help optimize performance behind the scenes.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>explainlikeimfive</category>
      <category>java</category>
      <category>database</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Is Java Playing Favorites: Primitives vs. Objects?</title>
      <dc:creator>levi</dc:creator>
      <pubDate>Thu, 13 Feb 2025 17:38:03 +0000</pubDate>
      <link>https://dev.to/levii07/is-java-playing-favorites-primitives-vs-objects-3mjm</link>
      <guid>https://dev.to/levii07/is-java-playing-favorites-primitives-vs-objects-3mjm</guid>
      <description>&lt;p&gt;Ever wondered what would happen if you typed:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Date date;&lt;br&gt;
date.now();&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Well, boom, instant compile-time error! Why? Because date is just a variable, not an object yet. It's like showing up at a party without your invitation—no object, no method access!&lt;/p&gt;

&lt;p&gt;To make things right, you have to create an object first, like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;date = new Date();&lt;/code&gt;&lt;br&gt;
Or, if you want to be fancy, you could:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Date yesterday = new Date();&lt;br&gt;
date = yesterday;&lt;/code&gt;&lt;br&gt;
But hold on a second—are these Java object variables the same as C++ pointers? Let’s dive into that. In Java, variables don’t work the same way they do in C++. Java variables are passed by value, and objects and variables are not the same thing.&lt;/p&gt;

&lt;p&gt;In Java:&lt;/p&gt;

&lt;p&gt;Objects are stored in heap memory.&lt;br&gt;
Reference variables that point to objects live in the stack.&lt;br&gt;
So, when it comes to passing by value, here’s how it goes down:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Passing Primitives:
Let’s start with a classic—primitives. These little guys are pass-by-value champs.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class PrimitivesUnitTest {
    @Test
    public void whenModifyingPrimitives_thenOriginalValuesNotModified() {
        int x = 1;
        int y = 2;

        // Before Modification
        assertEquals(x, 1);
        assertEquals(y, 2);

        modify(x, y);

        // After Modification
        assertEquals(x, 1);  // x stays unchanged!
        assertEquals(y, 2);  // y stays unchanged!
    }

    public static void modify(int x1, int y1) {
        x1 = 5;
        y1 = 10;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In this case, the x and y are primitive types, so they’re like little treasure chests of value. When we pass them to modify(), we don’t send the chests—just copies of the values inside them. Any changes to x1 and y1 won’t affect the original treasure chests x and y. Magic!&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Passing Objects:
Now, things get more interesting with objects. In Java, objects live in the heap, and reference variables are the keys to access them (stored in the stack).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When you pass an object, Java doesn’t send the object itself—it sends a copy of the reference (aka the key) that points to the object in the heap. It’s like giving someone a copy of your house key. They can go into your house, but you both have the same key! So, any changes made inside the house (object) will be reflected in both places.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class ModifyObjects {
    public static void main(String[] args) {
        Date date = new Date();
        modifyDate(date);
        System.out.println(date);  // Changes are reflected here!
    }

    public static void modifyDate(Date date) {
        date.setYear(2025);  // Modify the object in the heap
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we’re passing the reference to the date object, not the actual object itself. Both the caller and the method share the same object in memory. Any change made to date in the method will show up everywhere.&lt;/p&gt;

&lt;p&gt;Wrapping it Up: All About Passing by Value&lt;br&gt;
So, what’s the takeaway? Everything in Java is passed by value—but, when we deal with objects, it’s the reference value that gets passed, not the actual object. Objects are passed by reference, but the reference itself is passed by value. Confused yet?&lt;/p&gt;

&lt;p&gt;Here’s the recap:&lt;/p&gt;

&lt;p&gt;Primitives: You’re passing copies of the actual values.&lt;br&gt;
Objects: You’re passing copies of the reference to the object. You’re still sharing the same object in memory, though!&lt;br&gt;
In Java, pass-by-value is the rule. But with objects, it’s like passing the key to the kingdom, not the whole castle.&lt;/p&gt;

&lt;p&gt;So it was not that difficult posting my first article. &lt;/p&gt;

</description>
      <category>java</category>
      <category>primitive</category>
      <category>passbyvalue</category>
      <category>oop</category>
    </item>
  </channel>
</rss>
