Java Data Types

0
02 Datatypes
Java Data Types:
  • Data types are used to store data temporarily in computer through a program.
  • In real world we have different types of data in program to perform business required calculation and validations we must use data types concept.

Definition of data type:
  • Data type is something  which gives information about Size of the memory location and range of data that can be accommodated inside that location.
  • Possible legal operations those can be performed on that location.      
       Ex: on boolean data we cannot perform addition operation.
  • What type of result comes out from an expression when these types are used in side that expression.

Different Java data types:
In java mainly we have two types of data types.
1. Primitive types.
2. Referenced types.

1. Primitive types(8).
Used to store single value at a time. Based on type and range of data, primitive types are divided into 8 types.
i). byte.
ii). short.
iii). int.
iv). long.
v). float.
vi). double.
vii) char.
viii) boolean.
2. Referenced types(4).
Used to collect multiple of values using primitive types. primitive types are divided into 4 types.
i) Array.
ii) class.
iii) interface.
iv) enum.


// DataTypesDemo.java 
class DataTypesDemo
{
// primitive type variables creation
byte b=10;
int i=20;
char ch='a';

//array type variable creation
double[] d={1,2,3,4,5};

//predefined class String  type variable creation
String str="Hello";

public static void main(String[] args)
{
// User defined class DataTypesDemo variable creation
DataTypesDemo dtd=new DataTypeDemo();
}
}


// AddTwoInts.java 
class  AddTwoInts
{
public static void main(String[] args) 
{
int a = 10;
int b = 20;

int c = a + b;

int i1 = 10;
float  f1 = 20;

float f2 = i1 + f1;
//int i  = i1 + f1;
//=> float f2 = 10 + 20.0f;
//=> float f2 = 10.0f + 20.0f;
//=> float f2 = 30.0f;

byte b1 = 10; 
byte b2 = 20; 
byte b 3 = b1 + b2;

System.out.println(c);
System.out.println(f2);
}
}

Previous 
 1 
 2 
 3 
 4 
 5 
 6 
 Next

About the author

Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus. Aenean fermentum, eget tincidunt.

0 comments:

Recent Posts