Answer» The different sizes and values that can be stored in the variable are defined by data types. In Java, there are two types of data types:
Primitive Data Types in Java:- Primitive data types are the building blocks of data manipulation in the Java programming language. These are the most fundamental data types in the Java programming language. Following are the different primitive data types available in Java:-
| Data Type | Default Size | Description |
|---|
| boolean | 1 bit | Only two potential values are stored in the Boolean data type: true and false. Simple flags that track true/false circumstances are stored in this data type. | | char | 2 byte | A single 16-bit Unicode character is represented by the char data type. It has a value range of ‘\u0000’ (or 0) to ‘\uffff’ (or 65,535 inclusive). | | byte | 1 byte | It’s an 8-bit two-s complement signed integer. It has a value range of -128 to 127. (inclusive). It has a value of 0 by default. The byte data type is used to preserve memory in huge arrays where space is at a premium. Because a byte is four times smaller than an integer, it saves space. | | short | 2 bytes | A 16-bit signed two’s complement integer is the short data type. It has a value range of -32,768 to 32,767. (inclusive). It has a value of 0 by default. | | int | 4 bytes | A 32-bit signed two’s complement integer is represented by the int data type. Its range of values is (-2^31) to (2^31 -1)(inclusive). | | long | 8 bytes | A 64-bit two’s complement integer is the long data type. It has a value range of (-2^63) to (2^63 -1)(inclusive). | | float | 4 bytes | The float data type is a 32-bit IEEE 754 floating-point with single precision. If you need to preserve memory in big arrays of floating point integers, use a float (rather than a double). | | double | 8 bytes | A double data type is a 64-bit IEEE 754 floating-point with double precision. Like float, the double data type is commonly used for decimal values. For precise values, such as currency, the double data type should never be utilised. 0.0d is the default value. |
Non Primitive data types in Java:- The non-primitive data types in Java include classes, interfaces and arrays. We will discuss more on them in the upcoming topics.
|