Data types specify the different sizes and values that can be stored in the variable.In other words, a Java data type is a set of values and operations defined on those values. There are two types of data types:
- Primitive data types:The primitive data types include boolean, char, byte, short, int, long, float and double.
- Non-primitive data types:The non-primitive data types include Classes, Interfaces, and Arrays.
Primitive data types are a set of basic data types from which all other data types are constructed. Specifically it often refers to the limited set of data representations in use by a particular processor, which all compiled programs must use.
Non-primitive data types are also called ‘reference variables’ or ‘object references’ as they reference a memory location where data is stored. Non-primitive data types in Java are not predefined. They are created by the programmer.
Primitive data types in Java are built-in data types that are predefined whereas non-primitive data types are not predefined and are created by the programmer. A primitive data type always has a value while a non-primitive data type can be null.
Also Read: Difference Between Float And Double
Primitive Vs Non-primitive Data Types
|Primitive data structure||Non-primitive data structure|
|Primitive data structure is a kind of data structure that stores the data of only one type.||Non-primitive data structure is a type of data structure that can store the data of more than one type.|
|Examples of primitive data structure are integer, character, float.||Examples of non-primitive data structure are Array, Linked list, stack.|
|Primitive data structure will contain some value, i.e., it cannot be NULL.||Non-primitive data structure can consist of a NULL value.|
|The size depends on the type of the data structure.||In case of non-primitive data structure, size is not fixed.|
|It starts with a lowercase character.||It starts with an uppercase character.|
|Primitive data structure can be used to call the methods.||Non-primitive data structure cannot be used to call the methods.|
What You Need To Know About Primitive And Non-primitive Data Types
Primitive Data Type
- Data types that are provided by Java and allow specific type of data to be stored by a variable are called primitive types.
- The size is fixed.
- When a variable of primitive data type is defined only one memory location is allocated.
- To create a variable of primitive type 4. To ‘new’ keyword is not
Non-primitive Data Type
- Data types created by programmers which makes use of primitive type to create a variable as per the user’s requirement are called non-primitive or composite data types.
- The size depends on the number of members variables and their types.
- When an object of class type is defined the memory allocated will vary.
- To create an object variable we make use of ‘new’ keyword.