• Main Menu
  • Java Data Types


    Data types in the Java programming language are basically divided into two groups – primitive data types and object references. A primitive data type is a basic building block and has full built-in support. Many other languages also support composite data types, which are build on a combination of primitive data types and may or may not have built-in support.

    Java Primitive Data Types

    Let’s discuss the available primitive data types in Java. There are 8 primitive data types in Java, which are Boolean, Char, Byte, Short, Int, Long, Float, and Double.

    Data Type Purpose Contents Default Value*
    boolean Truth value true or false false
    char Character Unicode characters u0000
    byte Signed integer 8 bit two’s complement (byte) 0
    short Signed integer 16 bit two’s complement (short) 0
    int Signed integer 32 bit two’s complement 0
    long Signed integer 64 bit two’s complement 0L
    float Real number 32 bit IEEE 754 floating point 0.0f
    double Real number 64 bit IEEE 754 floating point 0.0d

    Note: A simple way to remember the Java primitive data types is by using this mnemonic aid: Be Careful, Bears Shouldn’t Ingest Large Furry Dogs.

    • Byte: A 8-bit signed and 2’s complement integer type. Its value range is from -128 to 127 (both inclusive).
    • Short: A 16-bit signed and 2’s complement integer type. Its value range from -32,768 to 32,767 (both inclusive).
    • Int: A 32-bit signed and 2’s complement integer type. Its value range from -2,147,483,648 to 2,147,483,647 (both inclusive).
    • Long: A 64-bit signed and 2’s complement integer type. Its value range from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (both inclusive).
    • Float: A 32-bit signed and single precision type.
    • Double: A 64-bit signed and double precision floating type.
    • Boolean: There are only 2 possible values – true and false.
    • Char: A single 16-bit Unicode character. Its value range from ‘\u0000’ (or 0) to ‘\uffff’ (or 65,535, both inclusive).

    Java Object References

    Java object references are variables which hold references to objects.

    Unlike Java primitive data types which store actual data, object references store only a reference to the actual data object.

    Got Something To Say:

    Your email address will not be published. Required fields are marked *

    Java
    } 189 queries in 0.338 seconds.