Data Types and its Categories in Java17/06/2017 2017-06-17 11:01
Data Types and its Categories in Java
Generally, data types are used to create variables where variables will hold values, as defined in the range of values of a datatype.
Java supports two categories of data types:
→ Primitive data types and
→ Non Primitive Data Types
Non Primitive Data Types
Non primitive data types are also called as reference data types
A Non Primitive Data Type is used to refer to an object.
In java variables of type class , arrays , enums and interface are represented as objects.
We will discuss this in later chapters like Arrays and Classes and Objects
Primitive Data Types
There are totally eight primitive data types in Java. They can be categorized as given below:
↪ Integer types (Does not allow decimal places)
↪ Rational Numbers(Numbers with decimal places)
→ Integer Type
|byte||1||-128 to 127|
|short||2||-32768 to 32767|
|int||4||-2147483648 to 2147483648|
|long||8||-9223,372,036,854,775,808 to 9223,372,036,854,775,807|
→ Rational Numbers
|float||4||-3.4 * 10^38 to 3.4 * 10^38(6 significant decimal digits)|
|double||8||-1.7*10^308 to 1.7*10^308(15 significant decimal digits)|
|char||2||0 to 65535|
Why Java uses 2 bytes for characters ?
→ In Java almost 18 international languages are supported .
→ Now, the characters and symbols of these languages cannot be accommodated in 1 byte space in memory ,so java takes 2 byte for characters.
→ Java supports UNICODE but C language supports ASCII code. In ASCII code we can represent characters of English language are present, so for storing all English latter and symbols 1 byte is sufficient.
→ But UNICODE character set is superset of ASCII in which all the characters which are available in 18 international languages are supported and it contains 65536 characters ranging from 0 to 65535
→ To assign unicode values we have two options:
Use the numeric value
Use the format ‘\uxxxx’ where xxxx is hexadecimal form of the value
OR ⇰Both means we are assigning letter A
|boolean||1 bits||true or false|