<?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: Buddika Abeykoon</title>
    <description>The latest articles on DEV Community by Buddika Abeykoon (@buddika_b).</description>
    <link>https://dev.to/buddika_b</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%2F736353%2F3de32c57-efad-413c-8f11-065b211df81c.jpeg</url>
      <title>DEV Community: Buddika Abeykoon</title>
      <link>https://dev.to/buddika_b</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/buddika_b"/>
    <language>en</language>
    <item>
      <title>Method Calling Stack in Java</title>
      <dc:creator>Buddika Abeykoon</dc:creator>
      <pubDate>Mon, 25 May 2026 03:53:41 +0000</pubDate>
      <link>https://dev.to/buddika_b/method-calling-stack-in-java-25fd</link>
      <guid>https://dev.to/buddika_b/method-calling-stack-in-java-25fd</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MethodCallingStack&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;MyMethod&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Start MyMethod()"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"End MyMethod()"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[]){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Start main()"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"End main()"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What is the Stack memory?&lt;/p&gt;

&lt;p&gt;Stack memory is a temporary memory area used to store method calls and local variables. Every time a method runs, Java creates a stack frame for that method. Variables like int x = 100; are stored in stack memory. When the method finishes, its data is removed automatically from the stack.&lt;/p&gt;

&lt;p&gt;What is the Heap Memory?&lt;/p&gt;

&lt;p&gt;Heap memory is used to store objects and arrays created using the new keyword. Heap memory is shared by all methods in the program. For example, in Student s = new Student();, the object is stored in heap memory, while the reference variable s is stored in stack memory. Heap memory keeps objects until they are removed by Java’s Garbage Collector.&lt;/p&gt;

&lt;p&gt;Working of Method Calling Stack!&lt;/p&gt;

&lt;p&gt;This program explains how the method calling stack works in Java. When the program starts, the main() method is loaded into stack memory, and the local variable x = 100 is stored inside the main() stack frame. If MyMethod() is called, a new stack frame is created above the main() frame, and its local variable x = 200 is stored there. Each method has its own separate variables in the stack memory. When a method finishes, its stack frame is removed automatically. This program does not create any objects, so heap memory is not used here.&lt;/p&gt;

</description>
      <category>java</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Recursive Factorial Program in Java</title>
      <dc:creator>Buddika Abeykoon</dc:creator>
      <pubDate>Mon, 18 May 2026 17:23:52 +0000</pubDate>
      <link>https://dev.to/buddika_b/recursive-factorial-program-in-java-gka</link>
      <guid>https://dev.to/buddika_b/recursive-factorial-program-in-java-gka</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RecursiveFactorial&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Base case&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;factorial&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Recursive call&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;factorial&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Factorial of "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" is: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This program is used to calculate the factorial of a number using recursion in Java. Recursion means a method calls itself repeatedly until a stopping condition is reached. In this program, the factorial() method checks whether the number is 0 or 1. If it is, the method returns 1, because the factorial of 0 and 1 is always 1. This is called the base case and it stops the recursion. If the number is greater than 1, the method multiplies the number by the factorial of the previous number using factorial(n - 1). For example, when the number is 5, the calculation happens as follows,&lt;br&gt;
                     5!=5×4×3×2×1=120&lt;br&gt;
In the main method, the number 5 is stored in a variable, the factorial() method is called, and the final answer is printed on the screen. The output of the program is “Factorial of 5 is: 120”.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Reason Why j is Always 0 in the Output</title>
      <dc:creator>Buddika Abeykoon</dc:creator>
      <pubDate>Tue, 12 May 2026 02:49:05 +0000</pubDate>
      <link>https://dev.to/buddika_b/reason-why-j-is-always-0-in-the-output-764</link>
      <guid>https://dev.to/buddika_b/reason-why-j-is-always-0-in-the-output-764</guid>
      <description>&lt;p&gt;public class Main&lt;br&gt;
{&lt;br&gt;
    public static void main(String[] args) {&lt;br&gt;
        System.out.println("Start\n");&lt;br&gt;
        int k=0;&lt;br&gt;
        System.out.println("k i j");&lt;br&gt;
        for(int i=0; i&amp;lt;10; i++) {&lt;br&gt;
            int j=0;&lt;br&gt;
            System.out.println(k+" "+i+" "+j);&lt;br&gt;
            j++;k++;&lt;br&gt;
        }&lt;br&gt;
        System.out.println("\n\nEnd");&lt;br&gt;
    }&lt;/p&gt;

&lt;h1&gt;
  
  
  }
&lt;/h1&gt;

&lt;p&gt;Start&lt;br&gt;
k i j&lt;br&gt;
0 0 0&lt;br&gt;
1 1 0&lt;br&gt;
2 2 0&lt;br&gt;
3 3 0&lt;br&gt;
4 4 0&lt;br&gt;
5 5 0&lt;br&gt;
6 6 0&lt;br&gt;
7 7 0&lt;br&gt;
8 8 0&lt;br&gt;
9 9 0&lt;br&gt;
End&lt;/p&gt;

&lt;p&gt;j is always printed as 0 because it is declared inside the for loop. Every time the loop runs, a new variable j is created and its value starts again from 0. After printing, j increases by 1 using j++, but when the next loop iteration starts, j is reset back to 0. That is why the output always shows 0 for j.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>java</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why This Java Loop Is Not Infinite 🤔</title>
      <dc:creator>Buddika Abeykoon</dc:creator>
      <pubDate>Mon, 11 May 2026 05:31:35 +0000</pubDate>
      <link>https://dev.to/buddika_b/why-this-java-loop-is-not-infinite-51ie</link>
      <guid>https://dev.to/buddika_b/why-this-java-loop-is-not-infinite-51ie</guid>
      <description>&lt;p&gt;public class Main&lt;br&gt;
{&lt;br&gt;
    public static void main(String[] args) {&lt;br&gt;
        System.out.println("Start\n");&lt;br&gt;
        byte i;&lt;br&gt;
        for(i=0; i&amp;lt;10; i--) {&lt;br&gt;
            System.out.print(i+", ");&lt;br&gt;
        }&lt;br&gt;
        System.out.print("\b\b");&lt;br&gt;
        System.out.println("\n\n\"i\" value is "+i+"\n\nEnd");&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;Start&lt;/p&gt;

&lt;p&gt;0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23, -24, -25, -26, -27, -28, -29, -30, -31, -32, -33, -34, -35, -36, -37, -38, -39, -40, -41, -42, -43, -44, -45, -46, -47, -48, -49, -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69, -70, -71, -72, -73, -74, -75, -76, -77, -78, -79, -80, -81, -82, -83, -84, -85, -86, -87, -88, -89, -90, -91, -92, -93, -94, -95, -96, -97, -98, -99, -100, -101, -102, -103, -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -114, -115, -116, -117, -118, -119, -120, -121, -122, -123, -124, -125, -126, -127, -128, &lt;/p&gt;

&lt;p&gt;"i" value is 127&lt;/p&gt;

&lt;p&gt;End&lt;/p&gt;

&lt;p&gt;This loop may look like an infinite loop because the value of i keeps decreasing and will always seem to be less than 10. However, the variable i is declared as a byte, and in Java a byte can only store values from -128 to 127. The loop starts from 0 and keeps decrementing until it reaches -128. After that, Java cannot store -129 in a byte, so the value automatically wraps around to 127 due to overflow. Once i becomes 127, the condition i &amp;lt; 10 becomes false, and the loop terminates. That’s why this loop is not infinite.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>java</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why Float and Double Outputs Are Different?</title>
      <dc:creator>Buddika Abeykoon</dc:creator>
      <pubDate>Fri, 08 May 2026 08:59:06 +0000</pubDate>
      <link>https://dev.to/buddika_b/why-float-and-double-outputs-are-different-apo</link>
      <guid>https://dev.to/buddika_b/why-float-and-double-outputs-are-different-apo</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;float f = Long.MAX_VALUE;
double d = Long.MAX_VALUE;

System.out.println("Float max value is : "+ f);
System.out.println("Double max value is : "+ d);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;===============================================&lt;br&gt;
Float max value is : 9.223372E18&lt;br&gt;
Double max value is : 9.223372036854776E18&lt;br&gt;
===============================================*/&lt;/p&gt;

&lt;p&gt;When we assign Long.MAX_VALUE to float and double, both try to store a very large number. But float cannot keep many digits accurately, so Java rounds the value and shows a shorter number like 9.223372E18. double has higher precision, so it can store more digits and shows a more accurate value like 9.223372036854776E18. That’s why both outputs are different even though they come from the same value.&lt;/p&gt;

</description>
      <category>java</category>
      <category>softwareengineering</category>
      <category>softwaredevelopment</category>
    </item>
  </channel>
</rss>
