1.

Datatypes in Java

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 TypeDefault SizeDescription
boolean1 bitOnly 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.
char2 byteA 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).
byte1 byteIt’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.
short2 bytesA 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.
int4 bytesA 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).
long8 bytesA 64-bit two’s complement integer is the long data type. It has a value range of (-2^63) to (2^63 -1)(inclusive).
float4 bytesThe 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).
double8 bytesA 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.




Discussion

No Comment Found