DEV Community

S Sarumathi
S Sarumathi

Posted on

Primitive Datatype In Java

1. Primitive Data Types (Basic):
Primitive data types are basic built-in types that store actual values directly in memory.

Java has 8 Primitive Data Types
These store actual values

- Byte:
Stores small integer numbers
byte a = 10;
Program:

public class ByteExample {
    public static void main(String[] args) {
        byte a = 10;
        System.out.println("Byte value: " + a);
    }
}
Enter fullscreen mode Exit fullscreen mode

- Short:
Stores medium integer numbers
short b = 200;
Program:

public class ShortExample {
    public static void main(String[] args) {
        short b = 200;
        System.out.println("Short value: " + b);
    }
}
Enter fullscreen mode Exit fullscreen mode

- Int:
Stores integer numbers
int c = 1000;
Program:

public class IntExample {
    public static void main(String[] args) {
        int c = 1000;
        System.out.println("Int value: " + c);
    }
}
Enter fullscreen mode Exit fullscreen mode

- Long:
Stores large integer numbers
long d = 100000L;
Program:

public class LongExample {
    public static void main(String[] args) {
        long d = 100000L;
        System.out.println("Long value: " + d);
    }
}
Enter fullscreen mode Exit fullscreen mode

- Float:
Stores decimal numbers
float e = 10.5f;
Program:

public class FloatExample {
    public static void main(String[] args) {
        float e = 10.5f;
        System.out.println("Float value: " + e);
    }
}
Enter fullscreen mode Exit fullscreen mode

- Double:
Stores large decimal numbers
double f = 20.99;
Program:

public class DoubleExample {
    public static void main(String[] args) {
        double f = 20.99;
        System.out.println("Double value: " + f);
    }
}
Enter fullscreen mode Exit fullscreen mode

- char:
Stores single character
char g = 'A';
Program:

public class CharExample {
    public static void main(String[] args) {
        char g = 'A';
        System.out.println("Char value: " + g);
    }
}
Enter fullscreen mode Exit fullscreen mode

- Boolean:
Stores true or false values
boolean h = true;
Program:

public class BooleanExample {
    public static void main(String[] args) {
        boolean h = true;
        System.out.println("Boolean value: " + h);
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)