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

Categories of Data Type in Java

 

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)

(a) byte

(b) short

(c) int

(d) long

↪ Rational Numbers(Numbers with decimal places)

(a) float

(b) double

↪ Characters

char

↪ Conditional

boolean

→ Integer Type

TypeSize(in Bytes)Range
byte1-128 to 127
short2-32768 to 32767
int4-2147483648 to 2147483648
long8-9223,372,036,854,775,808 to 9223,372,036,854,775,807

→ Rational Numbers

TypeSize(in Bytes)Range
float4-3.4 * 10^38 to 3.4 * 10^38(6 significant decimal digits)
double8-1.7*10^308 to 1.7*10^308(15 significant decimal digits)

→ Characters

TypeSize(in Bytes)Range
char20 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
OR
Use the format ‘\uxxxx’ where xxxx is hexadecimal form of the value

For example:
char ch=65;
OR ⇰Both means we are assigning letter A
char ch=‘\u0041’;

→ Conditional

TypeSizeRange
boolean1 bitstrue or false
Data Types and its Categories in Java

Shubham Tripathi

Java Developer (Full Stack) , Passionate about creating impact on scale | striving for a continuous improvement | learning entire gamut of Computer technologies | Raising my technical skills & trying to become a better person everyday |

    See all posts by admin