Lang Package

What is the importance of SCP(String constant pool)?

What is the importance of SCP(String constant pool)?

What is the importance of SCP(String constant pool)? There are two ways to create a String object in Java: Using the new operator. For example, String str = new String("Java4us");. Using a string literal or constant expression). For example, String str="Java4us"; (string literal) or String str="Java" + "4us"; (string constant expression). In our program, if a String object is repeatedly required then it’s not recommended to create ...

Read More »

Difference between deep cloning and shallow cloning?

Difference between deep cloning and shallow cloning?

Difference between deep cloning and shallow cloning? The process of creating the exact duplicate object is called cloning. The main purpose of cloning is to maintain a backup copy and to preserve the state of an object. We can perform cloning by using clone() of the object class. We can perform cloning only for cloneable objects and object is said ...

Read More »

What is the Contract between equals and hashCode method?

What is the Contract between equals and hashCode method

What is the Contract between equals and hashCode method If two objects are equals by .equals() then their hashCode must be equals. That is two equivalent object should have the same hashCode that is if r1.equals(r2) is true then r1.hashcode==r2.hashcode is always true. Object class .equals() method and hashCode() method follows above contract hence whenever we are overriding .equals() method ...

Read More »

What is the Relation between equals() and (==) Operator?

What is the Relation between equals() and (==) Operator?

What is the Relation between equals() and (==) Operator? (==) operator is a binary operator in java which compares the two objects based on their location in the memory. That means if two reference variables are pointing to the same object in the memory then applying (==) operator on those reference variables will return true. You can apply (==) operator to both primitive types as ...

Read More »

Why do we have to override the equals() method in Java?

Why do we have to override the equals() method in Java?

Why do we have to override the equals() method in Java? We can use the equals method to check equality of two objects. The equals() method of java.lang.Object class acts the same as the == operator; that is, it tests for object identity rather than object equality. The implicit contract of the equals() method, however, is that it tests for equality rather than identity. Thus most ...

Read More »

What is the meaning of hashCode in Java?

What is the meaning of hashCode in Java?

What is the meaning of hashCode in Java? For every object a unique number generated by JVM which is nothing but hashCode. Hashcode won’t represent an address of the object. JVM will use hashCode while saving the object into hashing related data structures like HashTable, HashSet, HashSet, etc.. The main advantage of saving object based on HashCode is search operation ...

Read More »

Responsive WordPress Theme Freetheme wordpress magazine responsive freetheme wordpress news responsive freeWORDPRESS PLUGIN PREMIUM FREEDownload theme free