07/03/25 ----------- Q)Explain about cloning of an object? =>java.lang.Object class has clone() method. When clone method is called on any Java object, an exact copy of that object is created. This method is seldom used in real projects. Q)What is deserialization? =>The mechanism of converting a stream of bytes (an object stored into a file) into an object is known as deseralization. =>readObject() method of java.io.ObjectInputStream class is used to implement deserialization. =>When this method is called, JVM creates a brand new object in the Heap area of RAM but it doesn't call the constructor on that object. Q)What is the scenario in which, constructor of a class is called but object of that class is not created? =>When a sub class object is created, on that object, super class constructor is called. But super class object is not created. Q)What is the scenario in which, object is created but constructor is not called? =>during deserialization (when readObject() method is called on ObjectInputStream) Q)Explain about "Object" class. =>java.lang package has a class by name "Object". =>java.lang.Object class is the super class of all the classes in Java. =>java.lang.Object class has certain functionality(methods). This functionality is inherited to every Java object. =>java.lang.Object class has the following methods. 1)wait() 2)notify() 3)notifyAll() 4)clone() 5)hasCode() 6)toString() 7)equals() 8)finalize() 9)getClass() =>hashCode() method returns the hashCode of the object. "Hash Code" is an integer generated by JVM based on the actual memory address of an object. =>Hash Code of any two objects in the HEAP area of RAM is different. =>equals() method is used to compare two objects. If they are equal, this method returns true. Otherwise, false. class Employee{ int empno; Employee(int empno){ this.empno=empno; } public boolean equals(Employee e){ boolean flag=false; if(this.empno==e.empno){ flag=true; } return flag; } } class Test { public static void main(String[] args) { Employee e1=new Employee(101); System.out.println(e1.hashCode()); Employee e2=new Employee(101); System.out.println(e2.hashCode()); if(e1.equals(e2)){ System.out.println("Objects are equal"); } else{ System.out.println("objects are not equal"); } }//main }