Sunday, February 8, 2009

Java Data Types

In java any variable has a type ,any express as a type and every type is strictly defind.Compiler will check all asignments for type compatability .Hence java is considered as strong typed language.
Java Language is not considered as pure oop language because some non-object (primitive data types)we have to maintain in our code sun people has interduced wrapper class to convert primitive to object form.

Data type --------------------- Wrapperclass
byte ------------------------- Byte
short ------------------------- Short
char ------------------------- Character
int ------------------------ Integer
float ------------------------ Float
double ----------------------- Double
boolean ---------------------- Boolean
long ----------------------- Long
Primitive types:
Numeric types:
Integral types for whole numbers
byte short int long
Floating point data types:
float double
char for character data type
boolean for logical values
except boolean and char the remaining data types are signed datatypes.i.e we can represent both positive and negative numbers by using numerical datatype.

java byte Datatype :
size---------8bits or 1 byte
range------ -128 to +127
native numbers are represented in 2’s complement form
this data type is best suitable of your handling data in terms of streams from a file or network
byte b=100; (valid)
byte b=200; (invalid)-----PLP found int required byte

short Datatype:
size------------16 bits or 2 bytes
range--------- -2 pow 15 to + 2 pow 15-1 i.e -32768 to 32767
this data type is very rarely used type in java.but best suitable for 16 bit process(these 16 bit processer are completely out dated and hence also the short data type is out dated now a days)

int data type:
size----------- 32 bits or 4bytes
range-------- -2 pow 31 to 2 pow 31-1 i.e -2147483648 to +2147483648
in c language the size of int is varied from platform to platform .the c program written for 32 bit proccesser can not run on 16 bit processor.hence chance of failing of c programe is very high .if we change plaiform. As a result c is not considered as a robust language.
But in the case of java the size of any data type is fixed for any platform . hence chance of failing of java program is very very lass .if we change platform. As a result java is considered as a robust language.

Long datatype:
Size----------64 bits or 8bytes
Range------- -2 pow 63 to 2 pow 63 -1
If int is not enough to hold big values like the amount of distence trvelled by light in 1000 days,we shoud go for long datatype only.
Float datatype:
Size--------------32bits or 4 bytes
Range---------- -3.4e38 to + 3.4e38
For 6 to 7 decimal places of accuracy , we should for float data this is less accuracy.

Double datatype:
Size--------------64bits or 8 bytes
Range---------- -1.7e308 to + 1.7e308
For 14 to 15 decimal places of accuracy , we should for double data this is more accurency.

Boolean datatype:
The size of boolean is not applicable.(it is purely depend on the underlying jvm).range not applicable.
But allowed values are true or flase. TRUE or FALSE are not allowed.

Char datatype:
Size--------------16 bits or 2 bytes.
Range----------- 0 to 65535.
This is to providing unicodes for all the worldwide charater sets.


Post a Comment