The types of data are split into two groups:
1. Primitive data types: byte, short, int, long, float, double, boolean and char are included.
2. Non-primitive data types : such as strings, arrays, and classes.
Primitive data types
The size and type of variable values are determined by a primitive data type, and there are no additional methods.
In Java, there are eight primitive data types:
Size ( in bytes)
Description (in storage terms)
-128 to 127
-32,768 to 32,767
-2,147,483,648 to 2,147,483,647
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
fractional numbers upto 6-7 digits
fractional numbers upto 15 decimal digits
stores values of true or false
single character/ letter or ASCII values
1. The numbers
The forms of primitive numbers are split into two groups:
-Integer types, without decimals, store whole numbers, positive or negative (such as 123 or -456). Byte, Short, Int and Long are valid forms. The form you need to use depends on the numerical value.
-Floating point forms represent numbers containing one or more decimals with a fractional component. Two forms exist: float and double.
2. Integer types
Entire numbers from -128 to 127 can be stored in the byte data form. This can be used to save memory instead of int or other integer types if you are sure that the value will be between -128 and 127.
The short data type can store whole numbers from -32768 to 32767.
You can store complete numbers from -2147483648 to 2147483647 in the int data form. Generally,when we construct variables with a numeric value, the int data type is the preferred data type.
Entire numbers can be stored from -9223372036854775808 to 9223372036854775807 in the long data form. When int is not big enough to store the value, this is used. Remember that the value should end with "L":
Floating Types of Points
Whenever you need a number with a decimal, like 9.99 or 3.14515, you can use a floating point form.
Fractional numbers from 3.4e−038 to 3.4e+038 can be stored in the float data form. Remember that the value should end with "f":
Fractional numbers from 1.7e−308 to 1.7e+308 can be stored in the double data form. Remember that the value should end with "d":
With the Boolean keyword, a Boolean data form is declared and can only take true or false values.
To store a single character, the Char data type is used. Single quotes, such as 'A' or 'c':' must surround the character.
For storing a series of characters (text), the String data type is used. Values for strings must be surrounded by double quotes.
Non-primitive data types
Non-primitive types of data, since they refer to objects, are called reference types.
The primary distinction between the forms of primitive and non-primitive data is:
1. In Java, primitive forms are predefined (already defined). The programmer creates non-primitive types which are not specified by Java (with the exception of String).
2. For calling methods to perform such operations, non-primitive types can be used, while primitive types can not.
3. There's still a value for a primitive type, while non-primitive types can be nil.