Data Types in Java


☞A type identifies a set of values (and their representation in memory) and a set of operations that transform these values into other values of that set.

☞ Java is strongly typed language.

☞Two type of data types :

1. Primitive type (or Intrinsic Data Type)
2. Non-Primitive type (Reference/Object or Composite Data Type)

Primitive Data Types

☞Once a primitive data type has been declared its type can never change, although in most cases its value can change.

☞There are 8 primitive data types.

1. boolean
2. char
3. byte
4. short
5. int
6. long
7. float
8. double

Precision of float and double :

1) A float datatype has the capacity to store numbers upto 7 significant digits. Example : float a=0.4235445

2) A double datatype has the capacity to store numbers upto 15 significant digits. Example : double a=0.42354459846435

Non-Primitive Data Type

☞A reference data type is used to refer to an object.

☞A reference variable is declare to be of specific and that type can never be changed.

☞Example : String, Scanner, Random, int[], String[] etc

☞Reference variables store addresses