QA Stacks

What is Data Types in Java...?

Data Types in Java

Data type is divided into 2 types.
1.    Primitive 
•    Boolean – (1 bit But boolean size is not fixed – JVM will decide the size of Boolean)
•    char – 2 byte
•    byte – 8 bit (1byte = 8 bit)
•    short – 2 byte
•    int – 4 byte
•    long – 8 byte
•    float – 4 byte
•    double – 8 byte

2.    Non – Primitive
•    String
•    Array
•    Class
•    Structure
•    Union

What is the deference between Primitive and Non-Primitive?
Ans :- Primitive Data types size is fixed were Non-Primitive Data types size is not fixed.
Lets understand with one example
char = ‘a’;    char size = 2 byte right.?
String1 = ‘swapnil’  
Now consider 1 char = 2 byte and if we check char in String1 is  = 7 so 2*7 = 14 byte right..?
Now another one 
String2 = ‘nikita’
Again if we check char in String2 is = 6 so 2*6 = 12 byte right..?
String1 is 14 byte and string2 is 12 byte
That’s why String size is not fixed