Wednesday, December 28, 2016

Data Types in Java

Tags

DATA TYPES IN JAVA :

Following are the 8 Basic Data Types in Java:

1. int - Integer
2. short - Short Integer
3. long - Long Integer
4. char - Character
5. float - Single Precision Floating point
6. double - Double Precision floating point
7. boolean - true/false
8. byte -  8-bit integer


Following Program Illustrates various data types -:

public class datatypes {
public static void main(String[] args) {

int num=1000000; //integer variable
short s=5000; //short variable
long l=900000000; //long variable
char c='c'; //char variable
float f =159.55f; //float variable ('f' keyword should be used for float)
double d=95735.561; //double variable
boolean b=true; //boolean variable

System.out.println("Value of num is " + num);
System.out.println("Value of s is " + s);
System.out.println("Value of l is " + l);
System.out.println("Value of c is " + c);
System.out.println("Value of f is " + f);
System.out.println("Value of d is " + d);
System.out.println("Value of b is " + b);
}
}





Note:-
1. The name of Source File should be exactly the same as the name of outer class.
2. In order to use float variable, keyword 'f' must be added at the end of its value.
3. '+' operator is used to combine output line and value.