Data Types

Data Types

Previous Home Next

 

The type of value that a variable hold is called a data type. Java  support  primitive(predefine in java language) 

data types.These are byte,int,short,long,char,float,double, and Boolean.

DataInputStream class lets an application read primitive data types from an  input stream in a machine independent way.
DataOutputStream class lets an application write primitive data types to an  output stream in a portable way.
java.lang package contains Data I/O stream files.

 Data type=byte
size in byte=1
size in bit=8
value= signed integer (range from-128to 127)
wrapper=java.lang.byte

Data type =integer
size in byte=4
size in bit=32 (range from -2,147,483,648 to 2,147,483,647)
value=signed/unsigned integer
wrapper=java.lang.integer

Data type=short
size in byte=2
size in bit=16
value=signed/unsigned integer(range from -32768 to 32767)
wrapper=java.lang.short

Data type=long
size in byte=8
size in bit=64
value=signed / unsigned integer
wrapper=java.lang.long
 
Data type=char
size in byte=2
size in bit=16
value=unicode character
wrapper=java.lang.char

Data type= float
size in byte=4
size in bit=32
value=real number/floating number
wrapper=java.lang.float

data type =double
size in byte=8
size in bit=64
value=real number/floating number
wrapper=java.lang.double

Data type =Boolean
size in byte=1
size in bit=8
value=true/false
wrapper=java. lang.Boolean

double price;
int unit;
double total = 0.0;
This is how the data type defined in java
the price of an item define in double which may be a decimal value
the unit of items define in int because they must be whole number value
the total cost amount of items also kept in double as it would also comes in floating value.

 
public class AddNumbers
{
public static void main(String[] args) {
System.out.println("Addition of two numbers!");
int a = 5;
int b =10;
int sum = a + b;
System.out.println("Sum: " + sum);
}
}


In above example has two variables of  int data type which are used and store the numbers ,the result will also store in
int data type.

The output of the above example is integer value i.e 15 
Previous Home Next