1. Primitive Data Types
Data types that a programming language pre-defines are called primitive data types. These data types can store a specific type and size of variable.
Basic primitive data types available in java are:
This data type stores values which are either true or false and is used to track true or false conditions for simple flags.
When it is required to save memory in arrays, we a byte data type that is capable of doing so because it is smaller than an integer (4 times) and can be used in place of the int data type.
-128 to 127
A 16-bit data type that is used to store characters is called char data type.
‘\u0000’ to ‘\uffff’ or 0 to 65,535.
Another 16-bit data type that is used to save memory is the short data type.
-32,768 to 32,767.
Int data type is a basic 32-bit data type that is used for integral values by default.
-2,147,483,648 to -2,147,483,647
The long data type provides a bigger range of values as compared to int data type, moreover, it is a 64-bit two’s complement integer.
-9,223,372,036,854,775,808(-2^63) to 9,223,372,036,854,775,807(2^63 -1)
The float data type is a 32-bit datatype that is used for decimal numbers and is not used for exact numbers.
Similar to float data type, the double data type which is a 64-bit data type is used for decimal point numbers and this also is not used for exact numbers.
Now that we have a good understanding of the primitive data types let’s discuss non-primitive data types.
2. Non-Primitive Data Types
Data types that are user-defined and are not specified in the programming language are referred to as non-primitive data types.
The non-primitive data types in Java include
A string data type in Java is regarded as an object that stores text.
A class is a data type that is specified by a user that is used for the creation of objects. It specifies the properties or methods of objects that belong to a similar type.
Java arrays are referred to as data structures that are implemented as objects. In simple words, these can be regarded as objects that contain a specific number and type of values.
Java data types are categorized into the following types; primitive data types and non-primitive data types. Primitive data types are already specified in the programming language however, non-primitive data types are user-defined. Boolean, byte, char, short, int, long, float, and double fall under the category of primitive data types, whereas, string, classes, and arrays are classified in the category of non-primitive data types. We have discussed these data types in detail in this write-up.