<?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>Forem: silambarasan rajendran</title>
    <description>The latest articles on Forem by silambarasan rajendran (@e00049).</description>
    <link>https://forem.com/e00049</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%2F2959272%2F2f122c9f-78af-4007-ab5b-4b90d36397a1.jpg</url>
      <title>Forem: silambarasan rajendran</title>
      <link>https://forem.com/e00049</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/e00049"/>
    <language>en</language>
    <item>
      <title>day-40: Conditional Statements in Java</title>
      <dc:creator>silambarasan rajendran</dc:creator>
      <pubDate>Thu, 08 May 2025 04:16:11 +0000</pubDate>
      <link>https://forem.com/e00049/day-40-conditional-statements-in-java-35nn</link>
      <guid>https://forem.com/e00049/day-40-conditional-statements-in-java-35nn</guid>
      <description>&lt;p&gt;Conditional statements allow you to control the flow of your program based on different conditions. Java supports the following types:&lt;/p&gt;

&lt;p&gt;1). if statement&lt;br&gt;
2). if-else statement&lt;br&gt;
3). if-else-if ladder&lt;br&gt;
4). Nested if&lt;br&gt;
5). switch-case statement&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;1). if Statement *&lt;/em&gt;&lt;br&gt;
Executes a block of code only if the condition is true.&lt;/p&gt;

&lt;p&gt;Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (condition) {
    // Code to execute if condition is true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int age = 18;
if (age &amp;gt;= 18) {
    System.out.println("You are an adult.");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
You are an adult.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;2). if-else Statement *&lt;/em&gt;&lt;br&gt;
Executes one block if the condition is true, and another if false.&lt;/p&gt;

&lt;p&gt;Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (condition) {
    // Code if true
} else {
    // Code if false
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int num = 10;
if (num % 2 == 0) {
    System.out.println("Even");
} else {
    System.out.println("Odd");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
Even&lt;/p&gt;

&lt;p&gt;3). if-else-if Ladder&lt;br&gt;
Checks multiple conditions in sequence.&lt;/p&gt;

&lt;p&gt;Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (condition1) {
    // Code if condition1 is true
} else if (condition2) {
    // Code if condition2 is true
} else {
    // Code if all conditions are false
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example (Grading System)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int marks = 85;
if (marks &amp;gt;= 90) {
    System.out.println("Grade A");
} else if (marks &amp;gt;= 80) {
    System.out.println("Grade B");
} else if (marks &amp;gt;= 70) {
    System.out.println("Grade C");
} else {
    System.out.println("Grade D");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
Grade B&lt;/p&gt;

&lt;p&gt;4). Nested if&lt;br&gt;
An if inside another if.&lt;/p&gt;

&lt;p&gt;Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (condition1) {
    if (condition2) {
        // Code if both conditions are true
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example (Login System)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String username = "admin";
String password = "12345";

if (username.equals("admin")) {
    if (password.equals("12345")) {
        System.out.println("Login successful!");
    } else {
        System.out.println("Wrong password.");
    }
} else {
    System.out.println("Invalid username.");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
Login successful!&lt;/p&gt;

&lt;p&gt;5). switch-case Statement&lt;br&gt;
Used when you have multiple conditions based on a single variable.&lt;/p&gt;

&lt;p&gt;Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;switch (variable) {
    case value1:
        // Code for value1
        break;
    case value2:
        // Code for value2
        break;
    default:
        // Code if no case matches
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example (Day of Week)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int day = 3;
switch (day) {
    case 1:
        System.out.println("Monday");
        break;
    case 2:
        System.out.println("Tuesday");
        break;
    case 3:
        System.out.println("Wednesday");
        break;
    default:
        System.out.println("Invalid day");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
Wednesday&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important Notes on switch-case:&lt;/strong&gt;&lt;br&gt;
break prevents "fall-through" (execution of subsequent cases).&lt;/p&gt;

&lt;p&gt;default runs if no case matches.&lt;/p&gt;

&lt;p&gt;Java 14+ supports switch expressions (simplified syntax).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Takeaways&lt;/strong&gt;&lt;br&gt;
Statement   Use Case&lt;br&gt;
if  Single condition check&lt;br&gt;
if-else Two possible outcomes&lt;br&gt;
if-else-if  Multiple conditions&lt;br&gt;
Nested if   Conditions inside conditions&lt;br&gt;
switch-case Multiple fixed-value checks&lt;br&gt;
Common Mistakes to Avoid&lt;br&gt;
❌ Using = instead of ==&lt;/p&gt;

&lt;p&gt;if (x = 5) → Wrong (assignment)&lt;br&gt;
if (x == 5) → Correct (comparison)&lt;/p&gt;

&lt;p&gt;❌ Missing break in switch-case&lt;/p&gt;

&lt;p&gt;Causes unintended fall-through.&lt;/p&gt;

&lt;p&gt;❌ Comparing strings with ==&lt;br&gt;
Use str1.equals(str2) instead.&lt;/p&gt;

&lt;p&gt;When to Use What?&lt;br&gt;
Use if-else for range-based conditions (e.g., age &amp;gt; 18).&lt;br&gt;
Use switch-case for fixed-value checks (e.g., day == 3).&lt;/p&gt;

&lt;p&gt;Ternary Operator vs. if Statement in Java&lt;br&gt;
Both are used for conditional logic, but they serve different purposes.&lt;/p&gt;

&lt;p&gt;1). Ternary Operator (? :)&lt;br&gt;
A shorthand for simple if-else conditions.&lt;br&gt;
Returns a value (used in assignments).&lt;/p&gt;

&lt;p&gt;Syntax&lt;br&gt;
variable = (condition) ? valueIfTrue : valueIfFalse;&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int age = 18;
String status = (age &amp;gt;= 18) ? "Adult" : "Minor";
System.out.println(status); // Output: "Adult"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When to Use?&lt;br&gt;
✔ Short, simple conditions (e.g., setting a variable).&lt;br&gt;
✔ Avoids multiple lines of if-else.&lt;/p&gt;

&lt;p&gt;Limitations&lt;br&gt;
❌ Cannot execute multiple statements.&lt;br&gt;
❌ Less readable for complex conditions.&lt;/p&gt;

&lt;p&gt;2). if Statement&lt;br&gt;
Used for general conditional logic.&lt;br&gt;
Can execute multiple statements.&lt;/p&gt;

&lt;p&gt;Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (condition) {
    // code if true
} else {
    // code if false
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int age = 18;
if (age &amp;gt;= 18) {
    System.out.println("Adult");
    System.out.println("You can vote!");
} else {
    System.out.println("Minor");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When to Use?&lt;br&gt;
✔ Complex conditions (multiple checks).&lt;br&gt;
✔ When you need multiple statements inside a branch.&lt;/p&gt;

&lt;p&gt;Key Differences&lt;br&gt;
Feature Ternary Operator (? :)  if Statement&lt;br&gt;
Purpose Returns a value Executes code blocks&lt;br&gt;
Best for    Simple conditions   Complex logic&lt;br&gt;
Multi-line  ❌ No  ✔ Yes&lt;br&gt;
Readability Good for short conditions   Better for long logic&lt;br&gt;
When to Choose Which?&lt;br&gt;
Use Ternary → Assigning values based on a condition.&lt;/p&gt;

&lt;p&gt;java&lt;br&gt;
int discount = (isMember) ? 10 : 0;&lt;br&gt;
Use if → Multiple operations or nested conditions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (temperature &amp;gt; 30) {
    System.out.println("Hot");
    turnOnAC();
} else {
    System.out.println("Cool");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Advanced: Nested Ternary (Avoid if Possible)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int num = 10;
String result = (num &amp;gt; 0) ? "Positive" : (num &amp;lt; 0) ? "Negative" : "Zero";
System.out.println(result); // "Positive"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⚠ Warning: Nested ternaries reduce readability. Prefer if-else for clarity.&lt;/p&gt;

&lt;p&gt;Final Advice&lt;br&gt;
Ternary → Best for one-liners (e.g., variable assignments).&lt;/p&gt;

&lt;p&gt;if → Best for complex logic (multiple conditions/statements).&lt;/p&gt;

&lt;p&gt;----------------------------------- assisted by ai ---------------------------------------&lt;/p&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>conditionalstatement</category>
    </item>
    <item>
      <title>day-34: looping statements in java</title>
      <dc:creator>silambarasan rajendran</dc:creator>
      <pubDate>Wed, 30 Apr 2025 05:54:53 +0000</pubDate>
      <link>https://forem.com/e00049/day-34-looping-statements-in-java-ccg</link>
      <guid>https://forem.com/e00049/day-34-looping-statements-in-java-ccg</guid>
      <description>&lt;p&gt;== --&amp;gt; Compares Values (Variables)&lt;/p&gt;

&lt;p&gt;Can we compare Objects?&lt;/p&gt;

&lt;p&gt;What is the difference between variables and objects?&lt;/p&gt;

&lt;p&gt;What is Variable?&lt;br&gt;
Named Container to store Data&lt;/p&gt;

&lt;p&gt;What is Object?&lt;br&gt;
Real Time Entity / Physical Entity / Sample of a class / Instance of a class / Memory Reference of a class / Combination of States and Behaviours&lt;/p&gt;

&lt;p&gt;Can we compare Objects?&lt;br&gt;
Yes, we can Objects. &lt;/p&gt;

&lt;p&gt;Passing Objects as arguments: &lt;/p&gt;

&lt;p&gt;==&lt;br&gt;
compare --&amp;gt; positive, negative, neutral&lt;/p&gt;

&lt;p&gt;equals --&amp;gt; true / false&lt;/p&gt;

&lt;p&gt;what is this keyword?&lt;br&gt;
this keyword refers to current object. &lt;/p&gt;

&lt;p&gt;How do you call non-static methods in a class?&lt;br&gt;
By using objects. &lt;br&gt;
object.method_name() &lt;/p&gt;

&lt;p&gt;player1.equals(player2); &lt;br&gt;
player1.equals(player2);&lt;/p&gt;

&lt;p&gt;public boolean equals(Players player2){&lt;br&gt;
  return false; &lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Where cant we use this keyword?&lt;br&gt;
Inside static blocks - static methods&lt;/p&gt;

&lt;p&gt;Where can we use this keyword?&lt;br&gt;
non-static methods&lt;/p&gt;

&lt;p&gt;== --&amp;gt; equals() method&lt;/p&gt;

&lt;p&gt;Primitive Datatypes --&amp;gt; == &lt;br&gt;
Non-primitive datatypes --&amp;gt; equals()&lt;/p&gt;

&lt;p&gt;Non-Primitive Datatypes are nothing but classes.&lt;/p&gt;

&lt;p&gt;We can pass the object as parameter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package learning1;

public class Muthu {
    int capacity; 
    int price; 

    public static void main(String[] args) {
        Silambarasan bike = new Silambarasan();
        Muthu muthu = new Muthu(); 
        muthu.travel(bike);
        Muthu waterBottle = new Muthu(); 
        waterBottle.capacity = 500; 
        waterBottle.price = 50; 
        muthu.drink(waterBottle);

    }

    private void drink(Muthu waterBottle) {
        System.out.println("Price is " + waterBottle.price);    
    }

    private void travel(Silambarasan bike) {
        bike.ride();
        System.out.println(bike.name);
        bike.fill_petrol();
        //bike.sell();  
    }
}


package learning1;

public class Silambarasan {

    String name = "bajaj";

    private void sell(){
        System.out.println("Planning to sell ");
    }

    public void ride(){
        System.out.println("Long Ride to Pondy");
    }

    public void fill_petrol(){
        System.out.println("Tank Full");
    }

    public void service_bike(){
        System.out.println("Bike Service");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Switch Case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int day = 3;

        if (day == 1) {
            System.out.println("Monday");
        } else if (day == 2) {
            System.out.println("Tuesday");
        } else if (day == 3) {
            System.out.println("Wednesday");
        } else if (day == 4) {
            System.out.println("Thursday");
        } else if (day == 5) {
            System.out.println("Friday");
        } else if (day == 6) {
            System.out.println("Saturday");
        } else if (day == 7) {
            System.out.println("Sunday");
        } else {
            System.out.println("Invalid day number");
        }


public class Control_FlowState {

    public static void main(String[] args) {

        int day = 3;

        switch (day) {
            case 1:
                System.out.println("Monday");
                break;
            case 2:
                System.out.println("Tuesday");
                break;
            case 3:
                System.out.println("Wednesday");
                break;
            default:
                System.out.println("Invalid day number");
                break;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Work around:&lt;br&gt;
switch-case: Task: &lt;/p&gt;

&lt;p&gt;1) day = 1, day = 2, day = 3&lt;br&gt;
Wednesday&lt;br&gt;
2) Remove break from case  1, from case 2, from case 3&lt;br&gt;
If we remove the break statement, process execute the all the conditions. &lt;/p&gt;

&lt;p&gt;Monday&lt;br&gt;
Tuesday&lt;br&gt;
Wednesday&lt;br&gt;
Invalid day number&lt;/p&gt;

&lt;p&gt;3) Move default just above any case block. &lt;br&gt;
No, Changes&lt;br&gt;
4) Remove break statement from default. &lt;br&gt;
No, Changes&lt;br&gt;
5) Instead of using int day, try using float values. &lt;br&gt;
java.lang.Error: Unresolved compilation problem&lt;/p&gt;

&lt;p&gt;----------------------------- End of the Blog ----------------------&lt;/p&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>loopingstate</category>
      <category>whileloop</category>
    </item>
    <item>
      <title>Day-33: Conditional Statements in java</title>
      <dc:creator>silambarasan rajendran</dc:creator>
      <pubDate>Wed, 30 Apr 2025 05:04:36 +0000</pubDate>
      <link>https://forem.com/e00049/day-33-conditional-statements-in-java-cn6</link>
      <guid>https://forem.com/e00049/day-33-conditional-statements-in-java-cn6</guid>
      <description>&lt;p&gt;Beginner: Repeated Reading: Base Twist: &lt;/p&gt;

&lt;p&gt;DON'T SAY I DON'T KNOW&lt;br&gt;
ALWAYS SAY LET ME TRY&lt;br&gt;
DON'T THINK ABOUT ENTIRE OUTPUT&lt;br&gt;
THINK ABOUT VERY NEXT STEP&lt;br&gt;
KNOWN TO UNKNOWN&lt;br&gt;
WRITE DOWN THE KNOWN STEPS&lt;br&gt;
THINK ABOUT VARIABLE, ADD IF IT IS NECESSARY&lt;br&gt;
MICRO TO MACRO&lt;/p&gt;

&lt;p&gt;1). Normal Statements&lt;br&gt;
2). Conditional Statements&lt;br&gt;
3). Control Flow Statements&lt;/p&gt;

&lt;p&gt;Good Bad Ugly&lt;br&gt;
Gangers&lt;/p&gt;

&lt;p&gt;if GBU --&amp;gt; &lt;br&gt;
else if Gangers --&amp;gt; &lt;/p&gt;

&lt;p&gt;if statement should definitely have else if part - True&lt;br&gt;
else if statement should definitely have else part - True &lt;/p&gt;

&lt;p&gt;if it rains, take umbrella&lt;br&gt;
else&lt;/p&gt;

&lt;p&gt;else if part should definitely have if part  - True &lt;/p&gt;

&lt;p&gt;else part should definitely have else if part  - False&lt;br&gt;
else part should definitely have if part  - True&lt;/p&gt;

&lt;p&gt;else part should definitely have either if or else if or both - True&lt;/p&gt;

&lt;p&gt;if(no1&amp;gt;no2)&lt;br&gt;
else&lt;/p&gt;

&lt;p&gt;if(no1&amp;gt;no2)&lt;br&gt;
else if(no2&amp;gt;no1)&lt;br&gt;
else&lt;/p&gt;

&lt;p&gt;else part is mandatory / Compulsory always - False&lt;/p&gt;

&lt;p&gt;How many else if block can one if block have? &lt;br&gt;
How many else block can one if block have?&lt;/p&gt;

&lt;p&gt;else block should be added ONLY at the end of all if blocks  True / False&lt;/p&gt;

&lt;p&gt;if(sslc_1&amp;gt;sslc_2) --&amp;gt; if sslc_1 is greater than sslc_2&lt;/p&gt;

&lt;p&gt;1). Basic if Condition (Check Even/Odd):&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 EvenOddCheck {
    public static void main(String[] args) {
        int number = 10;

        if (number % 2 == 0) {
            System.out.println(number + " is even.");
        } else {
            System.out.println(number + " is odd.");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2). if-else if Ladder (Grade Calculator)&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 GradeCalculator {
    public static void main(String[] args) {
        int marks = 85;

        if (marks &amp;gt;= 90) {
            System.out.println("Grade: A");
        } else if (marks &amp;gt;= 80) {
            System.out.println("Grade: B");
        } else if (marks &amp;gt;= 70) {
            System.out.println("Grade: C");
        } else {
            System.out.println("Grade: D");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3). Nested if (Login System)&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 LoginSystem {
    public static void main(String[] args) {
        String username = "admin";
        String password = "12345";

        if (username.equals("admin")) {          // Outer if
            if (password.equals("12345")) {     // Nested if
                System.out.println("Login successful!");
            } else {
                System.out.println("Wrong password.");
            }
        } else {
            System.out.println("Invalid username.");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Uses String.equals() for comparison (not ==).&lt;/p&gt;

&lt;p&gt;Key Takeaways:&lt;br&gt;
1). Basic if-else: Single condition check.&lt;br&gt;
2). if-else if: Multiple conditions (evaluated top-down).&lt;br&gt;
3). Nested if: Condition inside another condition.&lt;/p&gt;

&lt;p&gt;Common Pitfalls to Avoid:&lt;br&gt;
Using = (assignment) instead of == (comparison).&lt;br&gt;
Forgetting braces {} for multi-line blocks.&lt;br&gt;
Comparing strings with == (use .equals() instead).&lt;/p&gt;

&lt;p&gt;Re-call the previous statements:&lt;br&gt;
Objects will call Constructors by default. &lt;br&gt;
Child Object behaves as Parent Object is known as Inheritance. &lt;/p&gt;

&lt;p&gt;Child Object = Parent Object &lt;br&gt;
If both the statements are correct, My Question is: &lt;/p&gt;

&lt;p&gt;Should Child Object call Constructor in Parent Class? Yes / No&lt;/p&gt;

&lt;p&gt;Consider I have many constructors in Parent Class. In that case, which constructor will be called by Child Object?&lt;/p&gt;

&lt;p&gt;Usually which constructor will be called when we create Objects? [Consider we have multiple constructors]&lt;br&gt;
Constructor which has matching Arguments will be called. &lt;/p&gt;

&lt;p&gt;new SuperMarket(10, "Rice", 5); &lt;/p&gt;

&lt;p&gt;-------------------------- End of Blog ------------------------------&lt;/p&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>conditionalstatement</category>
      <category>ifstate</category>
    </item>
    <item>
      <title>day-32: Getter and Setter Methods in Java - Simple Example</title>
      <dc:creator>silambarasan rajendran</dc:creator>
      <pubDate>Wed, 23 Apr 2025 03:01:09 +0000</pubDate>
      <link>https://forem.com/e00049/day-32-getter-and-setter-methods-in-java-simple-example-dbo</link>
      <guid>https://forem.com/e00049/day-32-getter-and-setter-methods-in-java-simple-example-dbo</guid>
      <description>&lt;p&gt;&lt;strong&gt;Getters and Setters in Java&lt;/strong&gt;&lt;br&gt;
Getters and setters are methods used to access (get) and modify (set) private variables in a class. They are a key part of encapsulation, which hides the internal state of an object and allows controlled access through methods.&lt;/p&gt;

&lt;p&gt;Why Use Getters &amp;amp; Setters?&lt;/p&gt;

&lt;p&gt;✔ Control access to private variables&lt;br&gt;
✔ Add validation before setting values&lt;br&gt;
✔ Make code more maintainable&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Person Class with Getter &amp;amp; Setter&lt;/strong&gt;&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 Jewellery_shop {

    private int gold_rate;

    // Getter method (must return gold_rate)
    public int getGoldRate() {
        return gold_rate;
    }

    // Setter method
    public void setGoldRate(int gold_rate) {
        this.gold_rate = gold_rate;
        System.out.println("Gold Rate set to: " + gold_rate);
    }
}


public class Customer {

    public static void main(String[] args) {
        Jewellery_shop js = new Jewellery_shop();

        System.out.println("Initial Gold Rate: " + js.getGoldRate());

        // Set new rate
        js.setGoldRate(90);

        // Print updated rate
        System.out.println("Updated Gold Rate: " + js.getGoldRate());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Best Practices / Rules for Getters and Setters:&lt;br&gt;
✅ Naming Convention:&lt;br&gt;
    Getter: getVariableName()&lt;br&gt;
    Setter: setVariableName(Type value)&lt;/p&gt;

&lt;p&gt;✅ Return Type:&lt;br&gt;
    Getter: Should return the variable (not void)&lt;br&gt;
    Setter: Should be void and accept one parameter&lt;/p&gt;

&lt;p&gt;✅ Encapsulation Rule:&lt;br&gt;
    Keep your variables private&lt;br&gt;
    Access them via public getters and setters&lt;/p&gt;

&lt;p&gt;----------------  Doc Asssite by AI -------------------------------&lt;/p&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>oop</category>
      <category>encapulation</category>
    </item>
    <item>
      <title>day-31: Getter and Setter Methods in Java - Simple Example</title>
      <dc:creator>silambarasan rajendran</dc:creator>
      <pubDate>Wed, 23 Apr 2025 02:59:02 +0000</pubDate>
      <link>https://forem.com/e00049/day-31-getter-and-setter-methods-in-java-simple-example-1epf</link>
      <guid>https://forem.com/e00049/day-31-getter-and-setter-methods-in-java-simple-example-1epf</guid>
      <description>&lt;p&gt;&lt;strong&gt;Getters and Setters in Java&lt;/strong&gt;&lt;br&gt;
Getters and setters are methods used to access (get) and modify (set) private variables in a class. They are a key part of encapsulation, which hides the internal state of an object and allows controlled access through methods.&lt;/p&gt;

&lt;p&gt;Why Use Getters &amp;amp; Setters?&lt;/p&gt;

&lt;p&gt;✔ Control access to private variables&lt;br&gt;
✔ Add validation before setting values&lt;br&gt;
✔ Make code more maintainable&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Person Class with Getter &amp;amp; Setter&lt;/strong&gt;&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 Jewellery_shop {

    private int gold_rate;

    // Getter method (must return gold_rate)
    public int getGoldRate() {
        return gold_rate;
    }

    // Setter method
    public void setGoldRate(int gold_rate) {
        this.gold_rate = gold_rate;
        System.out.println("Gold Rate set to: " + gold_rate);
    }
}


public class Customer {

    public static void main(String[] args) {
        Jewellery_shop js = new Jewellery_shop();

        System.out.println("Initial Gold Rate: " + js.getGoldRate());

        // Set new rate
        js.setGoldRate(90);

        // Print updated rate
        System.out.println("Updated Gold Rate: " + js.getGoldRate());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Best Practices / Rules for Getters and Setters:&lt;br&gt;
✅ Naming Convention:&lt;br&gt;
    Getter: getVariableName()&lt;br&gt;
    Setter: setVariableName(Type value)&lt;/p&gt;

&lt;p&gt;✅ Return Type:&lt;br&gt;
    Getter: Should return the variable (not void)&lt;br&gt;
    Setter: Should be void and accept one parameter&lt;/p&gt;

&lt;p&gt;✅ Encapsulation Rule:&lt;br&gt;
    Keep your variables private&lt;br&gt;
    Access them via public getters and setters&lt;/p&gt;

&lt;p&gt;----------------  Doc Asssite by AI -------------------------------&lt;/p&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>encapsulation</category>
    </item>
    <item>
      <title>day-31: this, super and inner class in java</title>
      <dc:creator>silambarasan rajendran</dc:creator>
      <pubDate>Tue, 22 Apr 2025 03:24:30 +0000</pubDate>
      <link>https://forem.com/e00049/day-31-this-super-and-inner-class-in-java-46dn</link>
      <guid>https://forem.com/e00049/day-31-this-super-and-inner-class-in-java-46dn</guid>
      <description>&lt;p&gt;The "this" Keyword in Java&lt;br&gt;
The this keyword in Java is a reference variable that refers to the current object of a class. &lt;br&gt;
It has several important uses:&lt;/p&gt;

&lt;p&gt;Main Uses of this:&lt;br&gt;
1). To refer to current class instance variables (to resolve ambiguity between instance variables and parameters)&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 Student {
    String name;

    public Student(String name) {
        this.name = name; // 'this.name' refers to instance variable
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2). To invoke current class constructor (constructor chaining)&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 Rectangle {
    int width, height;

    public Rectangle() {
        this(10, 10); // calls parameterized constructor
    }

    public Rectangle(int width, int height) {
        this.width = width;
        this.height = height;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Important Notes&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a). this cannot be used in a static context (static methods or static blocks)

b). this is automatically added by the compiler in many cases (like when calling instance methods)

c). It helps make code more readable and resolves naming conflicts

d). In event handling or anonymous classes, this can refer to different objects, so you might need to qualify it with the class name (e.g., ClassName.this)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Understanding this is fundamental to proper object-oriented programming in Java.&lt;/p&gt;

&lt;p&gt;The "super" Keyword in Java:&lt;br&gt;
The super keyword in Java is a reference variable that refers to the immediate parent class object. It's used to access parent class members (fields, methods, and constructors) from a subclass.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Main Uses of super&lt;/strong&gt;&lt;br&gt;
1). Accessing Parent Class Variables&lt;br&gt;
Used when child and parent classes have fields with the same name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Parent {
    String color = "white";
}

class Child extends Parent {
    String color = "black";

    void printColor() {
        System.out.println(super.color); // prints "white" (parent)
        System.out.println(color);       // prints "black" (child)
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2). Calling Parent Class Methods&lt;/p&gt;

&lt;p&gt;Used to call overridden methods from the parent class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Parent {
    void display() {
        System.out.println("Parent method");
    }
}

class Child extends Parent {
    void display() {
        super.display(); // calls parent's display()
        System.out.println("Child method");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Calling Parent Class Constructors&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Used to invoke parent class constructor (must be the first statement in child constructor):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Parent {
    Parent() {
        System.out.println("Parent constructor");
    }
}

class Child extends Parent {
    Child() {
        super(); // calls parent constructor (implicit if omitted)
        System.out.println("Child constructor");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Important Notes About super&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;super() must be the first statement in a constructor if used

If you don't write super(), the compiler automatically inserts a call to the no-arg parent constructor

You can pass parameters to super() to call specific parent constructors:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;super(parameter1, parameter2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;super cannot be used in static contexts (static methods or blocks)&lt;/p&gt;

&lt;p&gt;Unlike this, super is not a reference to an object - it's a keyword for special compiler handling&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;super vs this&lt;/strong&gt;&lt;br&gt;
Feature super   this&lt;br&gt;
Reference   Immediate parent class  Current class instance&lt;br&gt;
Constructor Calls parent constructor    Calls current class constructor&lt;br&gt;
Variables   Accesses parent class variables Accesses current class variables&lt;br&gt;
Methods Calls overridden parent methods Calls current class methods&lt;/p&gt;

&lt;p&gt;Understanding super is essential for proper inheritance and method overriding in Java.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inner Class in Java - Simple Explanation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An inner class is a class defined inside another class. It helps organize related classes together and can access all members (even private) of the outer class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Use Inner Classes?&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Better Encapsulation: Hide helper classes inside another class.

Access Outer Class Private Members: Inner classes can access private fields/methods of the outer class.

Cleaner Code: Group related classes logically.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Key Points&lt;/strong&gt;&lt;br&gt;
✔ Inner classes can be private, protected, or public.&lt;br&gt;
✔ Non-static inner classes cannot have static members (except static final constants).&lt;br&gt;
✔ Static nested classes can have static members.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example in Real Life&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of a Car (Outer Class) having an Engine (Inner Class). The Engine is part of the Car and can access its private components, but it doesn’t make sense to use the Engine outside the Car.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car {
    private String model = "Tesla";

    class Engine {
        void start() {
            System.out.println(model + "'s engine started!"); // Can access private model
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Inner classes help in organizing code logically and provide better encapsulation. Use them when a class is only meaningful inside another class! 🚀&lt;/p&gt;

&lt;p&gt;------------------------------ This is Doc assists by AI  --------------------------------&lt;/p&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>oop</category>
      <category>this</category>
    </item>
    <item>
      <title>day-30: enumeration in java</title>
      <dc:creator>silambarasan rajendran</dc:creator>
      <pubDate>Mon, 21 Apr 2025 00:34:06 +0000</pubDate>
      <link>https://forem.com/e00049/day-30-enumeration-in-java-mbe</link>
      <guid>https://forem.com/e00049/day-30-enumeration-in-java-mbe</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is enumeration?&lt;/strong&gt;&lt;br&gt;
An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it.&lt;/p&gt;

&lt;p&gt;In programming, an "enum type" (or enumeration) is a data type that consists of a set of named constants, allowing you to represent a fixed set of values, such as days of the week or colors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt;&lt;br&gt;
    Fixed Set of Values: Enums define a specific, limited set of possible values for a variable.&lt;br&gt;
    Named Constants: Each value in the enum is represented by a named constant, making the code more readable and maintainable.&lt;br&gt;
    Type Safety: Enums provide type safety, ensuring that a variable can only hold one of the defined enum values, preventing errors. &lt;/p&gt;

&lt;p&gt;Examples:&lt;br&gt;
    Days of the Week: enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }&lt;br&gt;
    Compass Directions: enum Direction { NORTH, SOUTH, EAST, WEST }&lt;br&gt;
    Color: enum Color { RED, GREEN, BLUE }&lt;br&gt;
    Status: enum Status { ACTIVE, INACTIVE, PENDING }&lt;/p&gt;

&lt;p&gt;How it's used:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Readability:
Enums make code easier to understand by using meaningful names instead of raw numerical values.
Maintainability:
When the set of possible values changes, you only need to modify the enum definition, not multiple places in the code.
Error Prevention:
Enums help prevent errors by ensuring that a variable can only hold one of the predefined values.
Type Safety:
Enums enforce type safety, ensuring that variables of an enum type can only hold values of that enum type. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In Different Programming Languages:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Java: public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>enumeration</category>
      <category>githubcopilot</category>
    </item>
    <item>
      <title>day-28: Java Interface Explained: Rules, Real-World Examples, and Multiple Inheritance</title>
      <dc:creator>silambarasan rajendran</dc:creator>
      <pubDate>Sun, 20 Apr 2025 12:39:40 +0000</pubDate>
      <link>https://forem.com/e00049/day-28-java-interface-explained-rules-real-world-examples-and-multiple-inheritance-2fni</link>
      <guid>https://forem.com/e00049/day-28-java-interface-explained-rules-real-world-examples-and-multiple-inheritance-2fni</guid>
      <description>&lt;p&gt;What is interface in java?&lt;br&gt;
Interface like contract between two of them. &lt;/p&gt;

&lt;p&gt;Interface methods always in implement in different class. &lt;/p&gt;

&lt;p&gt;You and company:&lt;br&gt;
1). 2 days leave can taken&lt;br&gt;
2). upskill &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1). Interface is not class - True&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
public interface Company_rules {

   int leaves = 10;
   boolean variable_pay = true;

    public void work();
    public void rotate_shift();
    public void relocate();
    public void upskill();
    public void apply_leave();
        // method define and can't implement, no body

}

public interface Player_rules {

    public int player_rules();
    public int practice();
}

public class Amma {

    public void eat() {
        System.out.println("have you had your dinner...");  
    }
}


public class Employee extends Amma implements Company_rules, Player_rules {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Employee empl1 = new Employee();
         empl1.work();

         System.out.println(Company_rules.leave); 
// Static variable from the interface can be access via interface name with variable name

         System.out.println(Employee.variable_pay); 
// Static variable from the interface can be access via implement 
class name        

    }

    @Override // definition by someone and implements
    public void work() {
        // TODO Auto-generated method stub

    }

    @Override
    public void rotate_shift() {
        // TODO Auto-generated method stub

    }

    @Override 
    public void relocate() {
        // TODO Auto-generated method stub
           System.out.println("move to blr...");

    }

    @Override
    public void upskill() {
        // TODO Auto-generated method stub

    }

    @Override
    public void apply_leave() {
        // TODO Auto-generated method stub

    }
    @Override
    public int player_rules() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int practice() {
        // TODO Auto-generated method stub
        return 0;
    }
}

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

&lt;/div&gt;



&lt;p&gt;// &lt;a class="mentioned-user" href="https://dev.to/override"&gt;@override&lt;/a&gt; means - method can be create by some and implement by someone&lt;/p&gt;

&lt;p&gt;2). If method is interface mode if we again abstract that will be consider as redundant method. - True&lt;/p&gt;

&lt;p&gt;3). methods in interface&lt;br&gt;
    return datatypes - public void apply_leave();&lt;br&gt;
    arguments - public void apply_leave(int leave_days);&lt;br&gt;
    method signature - access modifier - public, private, default, protect, final and static.&lt;/p&gt;

&lt;p&gt;Static is common for all. and it will be called by class name.&lt;/p&gt;

&lt;p&gt;final methods cannot be overridden. &lt;br&gt;
final fields cannot be changed.&lt;/p&gt;

&lt;p&gt;So, Interface won't support Final Key word.&lt;br&gt;
Private also won't support.&lt;/p&gt;

&lt;p&gt;interface also supports local variables:&lt;br&gt;
    public void apply_leave(int number);&lt;/p&gt;

&lt;p&gt;It will support global variables:&lt;br&gt;
   int leave = 10;&lt;br&gt;
   boolean variable_pay = true;&lt;/p&gt;

&lt;p&gt;if variable name is italy format that is static, in interface all the variables are static. &lt;/p&gt;

&lt;p&gt;Is java supports multiple inheritance? yes, not directly&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 Employee extends Amma implements Company_rules { 
// multiple inheritance

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Employee empl1 = new Employee();
         empl1.work();
         empl1.play();

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

&lt;/div&gt;



&lt;p&gt;Static variable from the interface can be access via interface name with variable name&lt;/p&gt;

&lt;p&gt;Static variable from the interface can be access via implement class name&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    {
         System.out.println(Company_rules.leave); 
         System.out.println(Employee.variable_pay); 

   }

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

&lt;/div&gt;



&lt;p&gt;Class can be more than one interfaces&lt;/p&gt;

&lt;p&gt;To create New Object:&lt;br&gt;
   Classname refer_name = new classname();&lt;br&gt;
   Calculator cal = new Calculator();&lt;/p&gt;

&lt;p&gt;For validation purpose interface can verify the employee class.&lt;br&gt;
This is also called as dynamic Biding. &lt;/p&gt;

&lt;p&gt;interface_name from_interface_reference = new Class_name();&lt;br&gt;
parent_class partent_Object = new parent_class();&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     Company_rules manager = new Employee();
     manager.apply_leave(); //dynamic biding

     Amma object_amma = new Employee(); 
     object_amma.eat();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;you are allocating the new place for your manager and coach to validate the their given method in your class. &lt;/p&gt;

&lt;p&gt;Dynamic Binding example chart with teacher role:&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%2F8u4abqrcotuetfeit0nx.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%2F8u4abqrcotuetfeit0nx.png" alt="Image description" width="800" height="378"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;---------------------------------- end of the blog ---------------------------------------&lt;/p&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>interface</category>
      <category>multipleinheritance</category>
    </item>
    <item>
      <title>day-29: Java Interface Explained: Rules, Real-World Examples, and Multiple Inheritance</title>
      <dc:creator>silambarasan rajendran</dc:creator>
      <pubDate>Sun, 20 Apr 2025 12:22:09 +0000</pubDate>
      <link>https://forem.com/e00049/day-29-java-interface-explained-rules-real-world-examples-and-multiple-inheritance-e4e</link>
      <guid>https://forem.com/e00049/day-29-java-interface-explained-rules-real-world-examples-and-multiple-inheritance-e4e</guid>
      <description>&lt;p&gt;What is interface in java?&lt;br&gt;
Interface like contract between two of them. &lt;/p&gt;

&lt;p&gt;Interface methods always in implement in different class. &lt;/p&gt;

&lt;p&gt;You and company:&lt;br&gt;
1). 2 days leave can taken&lt;br&gt;
2). upskill &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1). Interface is not class - True&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
public interface Company_rules {

   int leaves = 10;
   boolean variable_pay = true;

    public void work();
    public void rotate_shift();
    public void relocate();
    public void upskill();
    public void apply_leave();
        // method define and can't implement, no body

}

public interface Player_rules {

    public int player_rules();
    public int practice();
}

public class Amma {

    public void eat() {
        System.out.println("have you had your dinner...");  
    }
}


public class Employee extends Amma implements Company_rules, Player_rules {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Employee empl1 = new Employee();
         empl1.work();

         System.out.println(Company_rules.leave); 
// Static variable from the interface can be access via interface name with variable name

         System.out.println(Employee.variable_pay); 
// Static variable from the interface can be access via implement 
class name        

    }

    @Override // definition by someone and implements
    public void work() {
        // TODO Auto-generated method stub

    }

    @Override
    public void rotate_shift() {
        // TODO Auto-generated method stub

    }

    @Override 
    public void relocate() {
        // TODO Auto-generated method stub
           System.out.println("move to blr...");

    }

    @Override
    public void upskill() {
        // TODO Auto-generated method stub

    }

    @Override
    public void apply_leave() {
        // TODO Auto-generated method stub

    }
    @Override
    public int player_rules() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int practice() {
        // TODO Auto-generated method stub
        return 0;
    }
}

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

&lt;/div&gt;



&lt;p&gt;// &lt;a class="mentioned-user" href="https://dev.to/override"&gt;@override&lt;/a&gt; means - method can be create by some and implement by someone&lt;/p&gt;

&lt;p&gt;2). If method is interface mode if we again abstract that will be consider as redundant method. - True&lt;/p&gt;

&lt;p&gt;3). methods in interface&lt;br&gt;
    return datatypes - public void apply_leave();&lt;br&gt;
    arguments - public void apply_leave(int leave_days);&lt;br&gt;
    method signature - access modifier - public, private, default, protect, final and static.&lt;/p&gt;

&lt;p&gt;Static is common for all. and it will be called by class name.&lt;/p&gt;

&lt;p&gt;final methods cannot be overridden. &lt;br&gt;
final fields cannot be changed.&lt;/p&gt;

&lt;p&gt;So, Interface won't support Final Key word.&lt;br&gt;
Private also won't support.&lt;/p&gt;

&lt;p&gt;interface also supports local variables:&lt;br&gt;
    public void apply_leave(int number);&lt;/p&gt;

&lt;p&gt;It will support global variables:&lt;br&gt;
   int leave = 10;&lt;br&gt;
   boolean variable_pay = true;&lt;/p&gt;

&lt;p&gt;if variable name is italy format that is static, in interface all the variables are static. &lt;/p&gt;

&lt;p&gt;Is java supports multiple inheritance? yes, not directly&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 Employee extends Amma implements Company_rules { 
// multiple inheritance

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Employee empl1 = new Employee();
         empl1.work();
         empl1.play();

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

&lt;/div&gt;



&lt;p&gt;Static variable from the interface can be access via interface name with variable name&lt;/p&gt;

&lt;p&gt;Static variable from the interface can be access via implement class name&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    {
         System.out.println(Company_rules.leave); 
         System.out.println(Employee.variable_pay); 

   }

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

&lt;/div&gt;



&lt;p&gt;Class can be more than one interfaces&lt;/p&gt;

&lt;p&gt;To create New Object:&lt;br&gt;
   Classname refer_name = new classname();&lt;br&gt;
   Calculator cal = new Calculator();&lt;/p&gt;

&lt;p&gt;For validation purpose interface can verify the employee class.&lt;br&gt;
This is also called as dynamic Biding. &lt;/p&gt;

&lt;p&gt;interface_name from_interface_reference = new Class_name();&lt;br&gt;
parent_class partent_Object = new parent_class();&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     Company_rules manager = new Employee();
     manager.apply_leave(); //dynamic biding

     Amma object_amma = new Employee(); 
     object_amma.eat();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;you are allocating the new place for your manager and coach to validate the their given method in your class. &lt;/p&gt;

&lt;p&gt;Dynamic Binding example chart with teacher role:&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%2F8u4abqrcotuetfeit0nx.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%2F8u4abqrcotuetfeit0nx.png" alt="Image description" width="800" height="378"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;---------------------------------- end of the blog ---------------------------------------&lt;/p&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>interface</category>
      <category>multipleinheritance</category>
    </item>
    <item>
      <title>day-27: Java Abstraction and Inheritance: Key Concepts, Code Examples, and Interview Insights</title>
      <dc:creator>silambarasan rajendran</dc:creator>
      <pubDate>Sat, 19 Apr 2025 18:55:41 +0000</pubDate>
      <link>https://forem.com/e00049/day-27-java-abstraction-and-inheritance-key-concepts-code-examples-and-interview-insights-22n0</link>
      <guid>https://forem.com/e00049/day-27-java-abstraction-and-inheritance-key-concepts-code-examples-and-interview-insights-22n0</guid>
      <description>&lt;p&gt;*&lt;em&gt;Note: *&lt;/em&gt;&lt;br&gt;
Always we try to approach the problem logically. &lt;/p&gt;

&lt;p&gt;Abstract Classes Can have at least one abstract method? True&lt;/p&gt;

&lt;p&gt;Abstract classes SHOULD have at least one abstract method? False.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package educationloanpackage;

   public abstract class Bank {

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

&lt;/div&gt;



&lt;p&gt;Abstract Methods are decleared to have no body, leaving their implementation to sub classes.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Abstraction: *&lt;/em&gt;&lt;br&gt;
Inheritance, Polymorphism  we need to know.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package educationloanpackage;

public abstract class Parents {

    public abstract void study();

        public void distribute_choco(){

        }

    public void grow() {
        System.out.println("Take Care");        
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }
}

package educationloanpackage;

public class Children extends Parents {

        @Override // annotation - metadata - data about data    
    public void study() {
        System.out.println("LLB Laws...");

    }
       // can't decrease the access...
       private void distribute_choco(){

       }

       public static void main(){
       Children ch = new Children(); // Inheritance
       ch.study(); // abstract and run time polymorphism
       ch.distribute_choco(); 
       ch.grow();

      }
}

public abstract class Child2 {
    // child class also abstract
    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }
}


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

&lt;/div&gt;



&lt;p&gt;Super --&amp;gt; Superior (or) Parent - Super - base&lt;br&gt;
Subordinate --&amp;gt; Child - Sub - Derived &lt;/p&gt;

&lt;p&gt;We can't change the parent class method's access modifier. But can increase the access modifier&lt;/p&gt;

&lt;p&gt;Like private to public... &lt;/p&gt;

&lt;p&gt;Abstract methods --&amp;gt;&amp;gt; Access Maintain --&amp;gt; Increase&lt;/p&gt;

&lt;p&gt;What is Inheritance? &lt;br&gt;
 Child Object Behaves as Parent Object. &lt;/p&gt;

&lt;p&gt;Parent child Loosely coupled Relationship&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interview Questions:&lt;/strong&gt;&lt;br&gt;
1). Abstract class should have at least one abstract method - False&lt;br&gt;
2). Abstract Classes can be instantiated --&amp;gt; False&lt;br&gt;
3). Abstract Classes can be have normal  --&amp;gt; True&lt;br&gt;
4). Final Classes can't be inherited --&amp;gt; True&lt;br&gt;
5). Final Classes can't be used in Inheritance - True (It will be child class).&lt;br&gt;
Final classes can't have sub-Classes.&lt;/p&gt;

&lt;p&gt;6). Abstract classes should sub classes --&amp;gt; True&lt;br&gt;
7). Can we have abstract final class --&amp;gt; False&lt;/p&gt;

&lt;p&gt;8). We cannot create objects for abstract classes - True&lt;br&gt;
9). Object is very closely related with constructors --&amp;gt; True&lt;br&gt;
10). Can we have constructor is abstract class? - True&lt;/p&gt;

&lt;p&gt;11). When constructors will be called? &lt;br&gt;
   When object is created.&lt;/p&gt;

&lt;p&gt;Abstract class won't have object we can call the parent's class constructor using child class object.&lt;br&gt;
Child Object = Parent Object&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public abstract class Parents{ 

    Public Parents{
     System.out.println("this is parent constract");
   }

}

public class Child extends Parents{

   public static void main(){
     Child ch = new Child(); // 11th question..
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;Interface: *&lt;/em&gt;&lt;br&gt;
   Abstract Class  = 0 to 100% Abstraction&lt;/p&gt;

&lt;p&gt;Interface is 100% Abstraction. &lt;/p&gt;

&lt;p&gt;As you've already learned, objects define their interaction with the outside world through the methods that they expose. Methods form the object's interface with the outside world; the buttons on the front of your television set, for example, are the interface between you and the electrical wiring on the other side of its plastic casing. You press the "power" button to turn the television on and off.&lt;/p&gt;

&lt;p&gt;Button, Plateform...&lt;/p&gt;

&lt;p&gt;In its most common form, an interface is a group of related methods with empty bodies.&lt;/p&gt;

&lt;p&gt;Ref for Interface: &lt;a href="https://docs.oracle.com/javase/tutorial/java/concepts/interface.html" rel="noopener noreferrer"&gt;https://docs.oracle.com/javase/tutorial/java/concepts/interface.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>oop</category>
      <category>abstraction</category>
    </item>
    <item>
      <title>day-26: Encapsulation and Abstraction in Java</title>
      <dc:creator>silambarasan rajendran</dc:creator>
      <pubDate>Wed, 16 Apr 2025 03:38:30 +0000</pubDate>
      <link>https://forem.com/e00049/day-26-encapsulation-and-abstraction-in-java-1ole</link>
      <guid>https://forem.com/e00049/day-26-encapsulation-and-abstraction-in-java-1ole</guid>
      <description>&lt;p&gt;&lt;strong&gt;Encapsulation:&lt;/strong&gt;&lt;br&gt;
In Java that involves bundling the data (variables) and the methods (functions) that operate on the data into a single unit, known as a class. It restricts direct access to some of an object's components and can prevent the accidental modification of data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) private    - Accessible within the same class only
2) default    - Accessible within the same package (no keyword used)
3) protected  - Accessible within the same package AND subclasses in other packages
4) public     - Accessible from anywhere
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use this    When you...&lt;br&gt;
--&amp;gt; import     Want to use a class from a different package&lt;br&gt;
--&amp;gt; extends    Want to inherit functionality from another class&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example code for protected:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package housingloandpackage;

public class HDFC {
    protected void education_load () {
        System.out.println("Educational load");
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
    }
}


package educationloanpackage;
import housingloandpackage.HDFC;

public class IOB extends HDFC {

    public static void main(String[] args) {
        IOB iob = new IOB();
        iob.education_load();
    }
}


package educationloanpackage;
import housingloandpackage.HDFC;

public class SBI {

    public static void main(String[] args) {
        HDFC hdfc = new HDFC();
        hdfc.emp_salary();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;IS-A Relationship only we can use extends key.&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; &lt;br&gt;
 --&amp;gt; If we extent the class we can use our own object&lt;br&gt;
or else we need to create new object for the class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Abstraction&lt;/strong&gt;&lt;br&gt;
Abstraction in Java is a fundamental object-oriented programming concept that involves hiding complex implementation details and presenting only the essential features to the user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public abstract class Parents {

    public abstract void study();

    public void grow() {
        System.out.println("Take Care");
    }

    public static void main(String[] args) {
        //Parents parents = new Parents(); 
        //parents.study(); Can't do that. 
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here:&lt;br&gt;
1). Class and Method can be abstract. &lt;br&gt;
2). It cannot be instantiated directly. - Can't create Object.&lt;br&gt;
3). If at least one method is abstract in a class, then the entire class should be abstract&lt;br&gt;
4). Abstract classes cannot be instantiated, but they can be subclassed.&lt;/p&gt;

&lt;p&gt;-------------------------- End of the Blog ------------------------&lt;/p&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>encapsulation</category>
      <category>abstraction</category>
    </item>
    <item>
      <title>day-25: Java Constructors - Complete Guide</title>
      <dc:creator>silambarasan rajendran</dc:creator>
      <pubDate>Tue, 15 Apr 2025 04:20:20 +0000</pubDate>
      <link>https://forem.com/e00049/day-25-java-constructors-complete-guide-277k</link>
      <guid>https://forem.com/e00049/day-25-java-constructors-complete-guide-277k</guid>
      <description>&lt;p&gt;&lt;strong&gt;1). Constructor:&lt;/strong&gt;&lt;br&gt;
A constructor in Java Programming is a block of code that initializes (constructs) the state and value during object creation.&lt;/p&gt;

&lt;p&gt;Constructors are special methods in Java used to initialize objects when they are created. They are called automatically when you instantiate a class using the new keyword.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;br&gt;
    1. Should know about local and global variables&lt;br&gt;
    2. Global variables to non static variables&lt;br&gt;
    3. Default value of global variables&lt;br&gt;
    4. Return data types&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constructor behavior:&lt;/strong&gt;&lt;br&gt;
  1). Constructor will be called automatically when objects are created&lt;br&gt;
  2). Constructor names should be a class names&lt;br&gt;
  3). Constructor will not have any return data types&lt;br&gt;
  4). Can be overloaded&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2). Types of Constructors&lt;/strong&gt;&lt;br&gt;
A). Default Constructor&lt;br&gt;
    If no constructor is defined, Java provides a default one.&lt;br&gt;
    It has no parameters and initializes fields to default values (0, null, false).&lt;/p&gt;

&lt;p&gt;B). No-Argument Constructor (User-Defined)&lt;br&gt;
    Explicitly written to initialize default values.&lt;/p&gt;

&lt;p&gt;C). Parameterized Constructor&lt;br&gt;
    Takes arguments to initialize objects with specific values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example code for Types of Constructors:&lt;/strong&gt;&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 SuperMarket {
    String product_name; 
    int price;
    int discount;

        // Parameterized Constructor
    public SuperMarket(String product_name, int price, int discount) {
        //Constructor
        this.product_name = product_name; 
        this.price    = price;  
        this.discount = discount;  
    }
        //Constructor Overloading
    public SuperMarket(String product_name, int price) {
        this.product_name = product_name; 
        this.price = price;  
    } 
        //Zero Argument Constructor / No-args Constructor
    public SuperMarket() { 
        System.out.println("Material from China");
    }

    public static void check() {
    //  System.out.println(this.product_name);
    }

    private void buy() {
        System.out.println(this.product_name + this.price);
    }

    public static void main(String[] args) {
        SuperMarket product1 = new SuperMarket("rice", 60,6); 
        SuperMarket product2 = new SuperMarket("Wheat", 50,5); 
        SuperMarket product3 = new SuperMarket("Coconut",25);

        SuperMarket product4 = new SuperMarket(); 

        System.out.println(product1.product_name);
        System.out.println(product2.product_name);
        product2.buy(); 
        //SuperMarket.check(); 
        check(); 
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Static Fields(variables) and Methods can be called using Class_name or directly. &lt;/p&gt;

&lt;p&gt;THIS Key word denotes current object. &lt;/p&gt;

&lt;p&gt;--------------------------------- End of the Blog --------------------------------------------&lt;/p&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>oop</category>
      <category>constructor</category>
    </item>
  </channel>
</rss>
