Skip to main content

Java Data Types



In java any variable has a type, any expression has  a type and every type is strictly defined. Compiler will check all assignments for type compatibility .Hence java is considered as strong typed language.
Java Language is not considered as pure OOP language because some non-objects (primitive data types) we have to maintain in our code .So sun people has introduced wrapper class to convert primitive to object form.

DATA TYPE

SIZE

RANGE

WRAPPER CLASS

Default value

byte

1byte

-128 to +127

Byte

0

short

2 bytes

-32768 to +32767

Short

0

int

4 bytes

-2147483648 to +2147483647(

Integer

0

long

8 bytes

-2 pow 63 to 9223372036854775808L

Long

0

float

4 bytes

-3.4e38 to + 3.4e38

Float

0.0

double

8 bytes

1.7e308 to + 1.7e308

Double

0.0

char

2 byte

0 to 65535

Character

Empty space

boolean

Not applicable

Not applicable. Only true or false

Boolean

false


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 type.so 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 type.so 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.

 

Comments

Popular posts from this blog

Yahoo! Calendar "Add Event" Seed URL Parameters

I can't seem to find any official documentation on this, so here are my notes. Some information gathered from  http://richmarr.wordpress.com/tag/calendar/ Other information gathered through trial and error, and close examination of the "Add Event" form on Yahoo!'s site. Yahoo! Calendar URL Parameters Parameter Required Example Value Notes v Required 60 Must be  60 . Possibly a version number? TITLE Required Event title Line feeds will appear in the confirmation screen, but will not be saved. May not contain HTML. ST Required 20090514T180000Z Event start time in UTC. Will be converted to the user's time zone. 20090514T180000 Event start time in user's local time 20090514 Event start time for an all day event. DUR value is ignored if this form is used. DUR 0200 Duration of the event. Format is HHMM, zero-padded. MM may range up to 99, and is converted into hours appropriately. HH values over 24 hours appear to be modulated by 24. Durations t...

Java literals:

Java literals:           A constant value which can be assigned to a variable is known as Literal.If we are assigning any outside range value for any data type ,we will get a compile time error saying Possible Loss of Precision found int required byte. For the integral data types (int ,byte,short,long) : we are allowed to specify a literal value in any   one of the following three forms. ---> Decimal literal (normal way) --->Octa literal (prefixed with 0 ) --->Hexa decimal (prefixed with 0x ) int x=10 ------------> Decimal int x=010 ------------>Octa int x=0X10 -------------->Hexa In the Hexa decimal notation for the extra digits we are allowed to specify either small or upper case a,b,c or A,B,C ( this is one of the few places where java is not case sensitive ). Example: class Sample { public static void main(String add[]) { int i = 10; int j=010; int k=0x10; System.out.println( i+”….”+j...