Compare Objects in Java

Compare Objects in Java. It represents real-life entities and is a fundamental unit of Object-Oriented Programming. A typical Java application creates a large number of objects, which interact via invoking methods. 

A Java object belongs to a Java class. Fields store an object’s state, whereas methods display the object’s activity. Templates, often known as classes, are used to build objects at runtime.

public class Main
{
public static void main(String[] args)
{
Double x = new Double(50.45555);
Long y = new Long(9887544);
System.out.println("Objects are not equal,it returns the value " + x.equals(y));
System.out.println("Objects are equal, it returns the value " + x.equals(50.45555));
}
}

 

Output:

Objects are not equal,it returns the value false
Objects are equal, it returns the value true

Object and Class in Java

A class is a user-defined type that describes the appearance of a specific type of object. A declaration and a definition make up a class description. A single instance of a class is called an object.

In Java, everything is linked to classes and objects, as well as their characteristics and methods. A automobile, for example, is an object in real life. The car has characteristics like weight and color, as well as procedures like drive and brake. A class functions similarly to an object function Object() or a “blueprint” for constructing things.

Double in Java

A double data type is a 64-bit IEEE 754 floating point with double precision. The Floating-Point Types, Formats, and Values section of the Java Language Specification specifies its range of values, which is beyond the scope of this discussion. This data type is usually the default for decimal values.

Long Int in Java

A 64-bit two’s complement integer is the long data type. You can represent an unsigned 64-bit long with a minimum value of 0 and a maximum value of 264-1 with the long data type in Java SE 8 and later. When you need a larger range of values than int can provide, use this data type.

Compiler: Click Here