1.Integer numbers-In this type of group there are four sub divided datatypes which are byte,short,int and long.Basically they all points to any integer number within their limit of width.
2.Float numbers-In this type of group there are two datatypes ,first one is float and other one is double.They both points to the floating values within their width limit.
3.Characters-In this type only character data type exist which points to any letters or number in specific digits.
4.Boolean group-This group have boolean data type which have only two special values which are /true’ and ‘false’.
Datatype with syntax example
Integer– As we have discussed there are mainly four types of sub divided data type byte,short,int,long.Below is list of their width.
Data type width in bits
byte 8
short 16
int 32
long 64
Syntax to declare this type of data
1. Byte
byte variable_name;
example:-> byte b;
2. Short
short variable_name;
example:-> short s;
3.Int
int variable_name;
example:->int a;
4.Long
long variable_name;
example:-> long l;
Floating numbers-As we discussed above in group division that mainly floating number’s group have two type of data type.
Data type width in bits
float 32
double 64
Syntax with example
1. Float
float variable_name;
example:->
float f;
2.Double
double variable_name;
example:->
double d;
Character type-In type of group it have only one type which is character type itself.It declares value like number or any alfabatical letters.It’s width is different from c/c++.
Data type width
char 8bits
Syntax with example
data type width
1. char
char variable_name;
example:->
char c;
note:
we can initialized value like ‘a’,’b’… inside the variable.
Booleans-This data type is used for checking condition directly.It have mainly two type of values. first one is ‘true and second is ‘false’.
Syntax:->
1. Boolean
bool variable_name;
example:->bool b;
note:-
we can only initialized value ‘true’ or ‘false’ inside the variable.
Let’s see the example which includes int,flat and char type of data.
problem:->>
write a java program to declare different type of variables having different data type
code–>>
class datatype{
public static void main(String args[]){
byte by=-2;
short s=20;
int a=10;
long b;
char c=’c’;
float d=1;
double e=12324.54567867;
b=10000;
System.out.println(“Value of byte variable= “+by);
System.out.println(“Value of short int variable= “+s);
System.out.println(“Value of int variable= “+a);
System.out.println(“Value of long int variable= “+b);
System.out.println(“Value of char variable= “+c);
System.out.println(“Value of float variable= “+d);
System.out.println(“Value of double variable= “+e);
}
}
output–>>
Value of byte variable= -2
Value of short int variable= 20
Value of int variable= 10
Value of long int variable= 10000
Value of char variable= c
Value of float variable= 1.0
Value of double variable= 12324.54567867
This is the simple program.First it declares different type of variables having different data type and then it can be initialized in different ways.After declaring and initializing phase we have simply prints the required result by sending request to the system.
If you have any difficulty regarding this then contact us or write a comment of your query! Thank you
Happy coding.