Tuesday, 26 May 2009

Data Types

Data Types
Every language has some data types so does Java
Data type defines the behaviour of variable on which it is applied
Different data types defined in Java language are
Integer types (4)
Name width (bits) Range
byte 8 -128 to 127
short 16 -32,768 to 32,767
int 32 -2,147,483,648 to 2,147,483,7
long 64 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807


  • All these types can hold non fraction values only
  • Range is the valid number which can be assigned to them

If a byte is assigned 150 , compile time error would be there

Floating types (2)

Name width (bits)

float 32

double 64

  • These are used to hold values with fractional part
  • Any fractional value is treated as double type by default by compiler

Character type

char : It is a 16 bit type used to hold single character enclosed in single literals ' '

boolean : This type holds either true or false only.

  • These are primitive types,corresponding to these are wrapper types which

will be discussed later

  • String data type is used to hold sequence of characters like world enclosed in double quotes " "
  • Moreover, In Java each class represents a data type

Let's move on to variables