System.*out*.println(new int[-5]); //here compile time error is not occured but when run time error is ocuured

in Array when initializer occur we cant define array size

when select element of an arrya we can pass a negative number or greater number than elements count but its give a exception at the run time ArrayIndexOutOfBoundsException

//here no error occured this can be used 
System.out.println(new String[]{"a","b","c"}[1]); //here we can access element of array going through the array memory location
 System.out.println(new String [4][2]); // here comes memory location of 2-dimensional array

Iterable protcol

In iterable protocol need data structure which followed iterator protocol ( in iterator protocol need a API for return a iterator )

In Iterator protocol mainly need to create a new iterator for every time when required a iterator and also need minimumly 2 protocols which are,

Shallow Copy vs Deep Copy Difference ( SE Concept )

shallow copy not copy a nested element and children (dependencies) only connect the parent elements copies → In Clone ( ) only happeing a shallow copy

Deep copy nested elements and children elements also copied

image.png

image.png

package c;

public class Demo {
    public static void main(String[] args) throws CloneNotSupportedException {
        Student s1 = new Student(001, "Bob", 10, "BackStreet", "NY", "USA");
        Student cloneOfs1 = s1.clone();
        System.out.println(s1 == cloneOfs1);
        System.out.println(s1.id == cloneOfs1.id);
        System.out.println(s1.name == cloneOfs1.name);
        System.out.println(s1.address == cloneOfs1.address); // here make a shallow copy cuz address memory location copy without creating an Address Object Clone

    }
}

class Student implements Cloneable{
    int id;
    String name;
    Address address;
    public Student(int id, String name, int houseNumber, String street, String city, String country) {
        this.id = id;
        this.name = name;
        this.address = new Address(houseNumber, street, city, country);
    }

    @Override
    public Student clone() throws CloneNotSupportedException {
        return (Student) super.clone();
    }
}

class Address implements Cloneable{
    int houseNumber;
    String street;
    String city;
    String country;

    public Address(int houseNumber, String street, String city, String country) {
        this.houseNumber = houseNumber;
        this.street = street;
        this.city = city;
        this.country = country;
    }

    @Override
    public Address clone() throws CloneNotSupportedException {
        return (Address) super.clone();
    }
}