A data type defines three components:
A primitive data type consists of an atomic, indivisible value, and is defined without the help of any other data types.
User-defined data types can have primitive data types and other user-defined data types.
Typically, a programming language does not let the programmers extend or redefine primitive data types.
Java provides many built-in primitive data types, such as int, float, boolean, char, etc.
For example, the three components that define the int primitive data type in Java are as follows:
You can give a name to a value of the int data type as
int count;
This statement defines that count is of int type.
count is a name (an identifier).
It can have one value from the set of values that defines values for the int data type.
For example, you can associate integer 1 to the name count using an assignment statement like
count = 1;
The following code shows how to declare variables of different data types using literals.
public class Main { public static void main(String[] args) { int anInt = 100; long aLong = 200L; byte aByte = 99; short aShort = -902; char aChar = 'A'; float aFloat = 99.98F; double aDouble = 999.89; /*from w w w . j ava 2 s.c om*/ // Print values of the variables System.out.println("anInt = " + anInt); System.out.println("aLong = " + aLong); System.out.println("aByte = " + aByte); System.out.println("aShort = " + aShort); System.out.println("aChar = " + aChar); System.out.println("aFloat = " + aFloat); System.out.println("aDouble = " + aDouble); } }