The value 2 is which type of datatype , A=3 is a variable of which data type , 20.58 is which type of data , what is the data type of value 459
Data types : It describes the type of data .Or it describes the data which we stored in a variable is of which type .
There are different types of data types as shown below:
- int
- float
- char
- String
int data type : It contains only integer value. we declare a integer variable by using int keyword. example-{1,2,3,4,0,14,45,67,....} These are the example of integer type. In 16bit application integer size is 2 bytes . But in 32bit and 64bit application the size of integer is 4 bytes.
int variable_name;
example: int marks;
marks=2; //here marks is a variable of integer type, which contains the value 2.
The value 2 is an integer type of data .
example : A=3 is a variable of which data type .
Answer : A=3 is a type of int data type.
example: what is the data type of value 459.
Answer : 459 is an integer value so the data type is int type.
float data type : It contains all floating type of data . We declare a float variable by using float keyword. The size of float is 4 bytes.
example:{3.0, 87.9, 2.09, 2.1, 22.0,.....} These are the example of float type.
Syntax for declaration of float variable .
float variable_name;
example : float average; // average is variable.
average=45.87 ; // Here average is a float type of data which contains 45.87, which is floating value.
Example : What is the data type for 20.58?
Answer : 20.58 is a float type of data .
For example : If we add an integer and float type of variable .
class Add{
public static void main(String args [ ]){
int a=10;
float b=45;
float c=a+b;
System.out.println(c); // The output will be 55.0 .
}
}
char data type : It contains only character value . ex-{ 'a' ,'b' , 'g' ,'r',.....} These are the example of char data type. Characters are always written within the single quotes('_'). char takes 1 byte.
Syntax for declaration of char variable .
char variable_name;
example: char section; // section is variable.
section=' b'; //Here b is a character which is stored in character data type variable (section ).
String data type : It contains only String value .ex-{"a", "abc", "raj", "lmn",....} these are the example of String . String are written within the double quotes ("_") . String is a sequence of character or combination of characters.it take one extra byte for null character.
for example : "a" - { 'a', '/o'} Here it takes 2 bytes one for a character and second for null character. One another example : "abc" - {'a' , 'b' , 'c' , '/o'} Here it takes 4 bytes . 3 for abc and one more for null character.Syntax for declaration of String variable.
String variable_name;
example: String name; // name is variable .
name="rose"; // Here name is String data type variable . which stored sequence of character In this example a variable name takes 5 bytes .