The various sizes and values that can be stored in a variable are determined by its data type. In Java, there are two categories of data types:
Data types that are considered primitive include booleans, chars, bytes, short ints, long ints, floats, and doubles. The types of non-primitive data Classes, Interfaces, and Arrays are examples of non-primitive data types.
Types of Primitive Data Types in JAVA
Boolean Data Type:- There are only two potential values that can be stored using the Boolean data type: true and false. Simple flags that track true/false situations are utilised with this data type.
Although the Boolean data type only specifies one piece of information, its exact “size” cannot be determined.
Byte Data Type:- An illustration of a basic data type is the byte data type. It is a signed, 8-bit integer with two’s complement. it has a value range of -128 to 127. (inclusive). Its minimum and maximum values are -128 and 127 respectively. 0 is the default value.
When memory savings are most needed, like in huge arrays, the byte data type is employed. Because a byte is 4 times smaller than an integer, it conserves space. As an alternative to “int,” it is also a data type.
Short Data Type:- A 16-bit signed two’s complement integer is the short data type. Its range of values is from -32,768 to 32,767 (inclusive). Its range of values ranges from -32,768 to 32,767. The default setting is 0.
Like the byte data type, the short data type can also be used to save memory. An integer is twice as small as a short data type.
Int Data Type:- A 32-bit signed two’s complement integer, or int, is the data type. Its value ranges between -2,147,483,648 (-31), to 2,147,483,647 (2-31), respectively (inclusive). 2,147,483,648 is its minimum value and 2,147,483,647 is its maximum value. The default setting is 0.
Unless there is no memory issue, the int data type is typically used as the default data type for integral values.
Long Data Type:- A two’s complement, 64-bit long data type is an integer. Between -9,223,372,036,854,775,808(-263) and 9,223,372,036,854,775,807(263 -1) are its possible values.
The value ranges from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. The default setting is 0. When you require a wider range of values than int can provide, the long data type is used.
Float Data Type:- A single-precision 32-bit IEEE 754 floating point is the float data type. It has an infinite value range. If you need to conserve memory in sizable arrays of floating point numbers, it is advised to use a float (instead of a double). Never use the float data type for precise values like currency. The default setting is 0.0F.
Double Data Type:- The float data type is a single-precision 32-bit IEEE 754 floating point. Its value range is limitless. It is recommended to use a float when dealing with large arrays of floating point integers to save memory (instead of a double). For precise values like currency, the float data type should never be used. 0.0F is the default setting.
Char Data Type:- One 16-bit Unicode character is contained in the char data type. Its value range is from 0 to ‘uffff’ (or ‘u0000’) (or 65,535 inclusive). Characters are stored using the char data type.
The primitive data types in JAVA are as mentioned above. For more insights on JAVA language, learners must go through the details of the bootcamp coding courses provided by Eduriefy.