java
Common Methods
Both StringBuffer and StringBuilder share similar methods: Method Description Example append(String s) Adds text to the end sb.append(" Java") insert(int offset, String s) Inserts text at given position sb.insert(5, " World") replace(int start, int end, String s) Replaces part of the string sb.replace(0, 5, "Hi") delete(int start, int end) Deletes characters sb.delete(0, 3) reverse() Reverses the string sb.reverse() capacity() Returns buffer capacity sb.capacity() length() Returns length of string sb.length()
Feature	StringBuffer	StringBuilder
Mutability	Mutable	Mutable
Thread-Safety	Yes (synchronized)	No (not synchronized)
Performance	Slower (due to thread-safety)	Faster
Use Case	When multiple threads are modifying the same string	When only one thread is working on the string 
                  
Use StringBuffer when thread safety is required.
Use StringBuilder for better performance in single-threaded code.
Both classes help improve performance when performing multiple string modifications. 
                  Method Overloading
Method Overloading occurs when: Two or more methods have the same name. They have different parameter lists (different number or type of parameters). They may have different return types, but the parameter list must be different. Note: Overloading is an example of compile-time polymorphism (also called static polymorphism).
Methods must have different parameter lists.
Return type alone cannot be used to overload a method.
Overloaded methods can have different access modifiers.
Overloading can happen in the same class or in a subclass.
public class Calculator {
    // Method with two int parameters
    public int add(int a, int b) {
        return a + b;
    }
    // Method with three int parameters
    public int add(int a, int b, int c) {
        return a + b + c;
    }
    // Method with double parameters
    public double add(double a, double b) {
        return a + b;
    }
    public static void main(String[] args) {
        Calculator calc = new Calculator();
        System.out.println("Sum of 2 ints: " + calc.add(10, 20));
        System.out.println("Sum of 3 ints: " + calc.add(10, 20, 30));
        System.out.println("Sum of 2 doubles: " + calc.add(5.5, 4.5));
    }
}