Difference Between Float and Double in Java

Both float and double data types represent floating point numbers in Java. The float data type is a single-precision 32-bit IEEE 754 floating point...
Java Inheritance

Java Inheritance and Composition

Inheritance and composition are the two common methods to reuse code in Java. Inheritance is also known as "IS-A Relationship", composition is known as...
Java Immutable Object

Immutable Objects in Java

Immutable objects are objects that cannot be changed once created. For instance, String is an immutable class in Java. Consider the code below, in the first...
Java Equals Hashcode

Equals and Hashcode Methods in Java

Many Java classes including collection classes (like HashMap, HashTable, HashSet) use hashCode() and equals() methods to compare objects. If two objects are equal, they should...

Java Defensive Copying

Defensive Copying is a term used for immutable objects. Briefly, you cannot change the state of an immutable object once created. In Java, String class...