Primitive data types: Primitive data types are the basic data types that are built into the Java language. Primitive data types are simple and hold a single value at a time, and they are stored in the memory stack. When you create a variable of a primitive data type, the variable stores the value itself, rather than a reference to an object containing the value. The primitive data types in Java include:
boolean: represents a true or false value
byte: represents an 8-bit signed integer value
short: represents a 16-bit signed integer value
int: represents a 32-bit signed integer value
long: represents a 64-bit signed integer value
float: represents a 32-bit floating-point value
double: represents a 64-bit floating-point value
char: represents a single 16-bit Unicode character
Here's an example of creating and initializing variables of primitive types in Java:
Reference data types: Reference types, on the other hand, are more complex and represent objects rather than simple values. When you create a variable of a reference type, the variable stores a reference (a memory address) to an object containing the value. Reference data types are also called non primitive data types.
Reference types include:
Strings: used to represent a sequence of characters
Arrays: used to represent a collection of values of the same data type
Classes: used to represent user-defined types
Here's an example of creating and initializing variables of reference types in Java:
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article