What is Datatype?

A data type is an attribute of data/value that tells the type of data held by a variable. Each data-type requires a different amount of memory and has some specific operations that can be performed through it.

Types of data-types in Java

  1. Primitive data-type
  2. Non-primitive data-type

Java data type tree

Primitive data-type

Primitive types are the most basic and predefined data types available in Java. Once a primitive data type has been declared its type can never change, although in most cases its value can change.

There are 8 primitive data types:

Data TypeDefault ValueDefault size
byte01 byte
short02 bytes
int04 bytes
long0L8 bytes
float0.0f4 bytes
double0.0d8 bytes
booleanfalse1 bit
char‘\u0000’2 bytes

See also – Java program to print size of different datatypes

Java data types example

public class DataTypeExample {

    public static void main(String[] args) {

        // Assign value
        char c = 'A';
        boolean valid = true;
        byte b = 123;
        short s = 12345;
        int i = 1234567890;
        long l = 12345678910L;
        float f = 12345.6F;
        double d = 1234567890.12345D;

    }
}