Primitive vs Object Data Types: Explore the Difference between Primitive and Object Data Types in Java
What is a Primitive Data Type?
The predefined data types of Java are known as primitive data types. The agenda of these data types is to determine the size and type of any values. It includes eight primitive data types: byte, long, short, int, double, float, char and boolean.
What is Object Data Type?
The object data type is also known as non-primitive or reference data type; these are not predefined ones; instead, we need to create them. For example, classes, interfaces, strings, arrays, etc.
Difference between Primitive and Object Data Types in Java
Sl. No. | Primitive Data Types | Object Data Types |
1 | Primitive data types are predefined. | Object data types are user-defined. |
2 | These data types are held in a stack. | In these data types, the original object is kept in the heap, and the reference variable is kept in the stack. |
3 | Two distinct variables are generated, as well as two separate assignments. This is to be noted that the values should be the same. | Here, two reference variables are generated, yet both highlight a similar article on the heap. |
4 | They do not contain a null value as the default value. | The reference variable’s default value is null. |
5 | Examples are: byte, float, double, char, boolean, etc. | Examples are: array, string, etc. |
Keep learning and stay tuned to BYJU’S to get the latest updates on GATE Exam along with GATE Eligibility Criteria, GATE 2024, GATE Admit Card, GATE Application Form, GATE Syllabus, GATE Cutoff, GATE Previous Year Question Paper, and more.
Also Explore,
- Difference between Abstract Class and Interface in Java
- Difference between Abstraction and Encapsulation in Java
- Difference between Aggregation and Composition in Java
- Difference between Hashset and Treeset in Java
- Difference between == and .equals() method in Java
- Difference between Stack and Heap Memory in Java
- Difference between Throw and Throws in Java
Comments