Basic data types in Java 8

Posted by outpost on Sun, 01 Dec 2019 18:24:01 +0100

What is data type

Baidu Encyclopedia: the definition of data type in data structure is a set of values and a set of operations defined on this set of values. Variable can also specify its data type when declaring a variable. All variables have data types to determine which data can be stored.
Therefore, by defining different types of variables, you can store integers, decimals, or characters in memory.

Basic data types of Java

The Java language provides eight basic types. Six numeric types (four integer, two floating-point), one character type, and one Boolean.

Java basic data size, default value and value range

Size, default value and value range of validation basic data in IDEA

public class DataType {
    static byte b;
    static short s;
    static int i;
    static long l;
    static float f;
    static double d;
    static char c;
    static boolean bool;

    public static void main(String args[]) {
        System.out.println("byte[Size:"+Byte.SIZE
                +", Default value:"+b
                +"; Data range:"+Byte.MIN_VALUE+" ~ "+Byte.MAX_VALUE+"]");
        System.out.println("short[Size:"+Short.SIZE
                +", Default value:"+s
                +"; Data range:"+Short.MIN_VALUE+" ~ "+Short.MAX_VALUE+"]");
        System.out.println("int[Size:"+Integer.SIZE
                +", Default value:"+i
                +"; Data range:"+Integer.MIN_VALUE+" ~ "+Integer.MAX_VALUE+"]");
        System.out.println("long[Size:"+Long.SIZE
                +", Default value:"+l
                +"; Data range:"+Long.MIN_VALUE+" ~ "+Long.MAX_VALUE+"]");
        System.out.println("float[Size:"+Float.SIZE
                +", Default value:"+f
                +"; Data range:"+Float.MIN_VALUE+" ~ "+Float.MAX_VALUE+"]");
        System.out.println("double[Size:"+Double.SIZE
                +", Default value:"+d
                +"; Data range:"+Double.MIN_VALUE+" ~ "+Double.MAX_VALUE+"]");
        System.out.println("char[Size:"+Character.SIZE
                +", Default value:"+c
                +"; Data range:"+(int)Character.MIN_VALUE+" ~ "+(int)Character.MAX_VALUE+"]");
        System.out.println("boolean[Default value:"+bool
                +"; Data range:"+Boolean.TRUE+" & "+Boolean.FALSE+"]");
    }
}

Operation result:

Topics: Java