DEV Community

Cover image for Java Data Types ?
Arul .A
Arul .A

Posted on

Java Data Types ?

-The java has Two Type of Data Types.These Are

  1. Primitive Data Types
  2. Non-Primitive Data Types

  • Primitive Data Types: (IT Has Eight Types)
  1. byte - Stores small integers from -128 to 127(1 byte).
    Used only when memory optimization actually matters.

  2. short - Stores integers from -32,768 to 32,767(2 bytes).
    Almost never used in real Java applications.

  3. int - Stores whole numbers within 32-bit range(4 Bytes).
    Default and most commonly used integer type.

  4. long - Stores very large whole numbers (64-bit)(8 Bytes).
    Use when int is not sufficient.

  5. float - Stores decimal numbers with single precision().
    Not accurate for financial or precise calculations.

  6. double - Stores decimal numbers with double precision.
    Default choice for decimal values in Java.

  7. char - Stores a single Unicode character.
    Uses 2 bytes and supports international characters.

  8. boolean - Stores only true or false.
    Used for conditions and logical decisions.

-Non -Primitive Data Types:

  1. String - Stores a sequence of characters as an object.
    Immutable and provides many built-in methods.

  2. Array - Stores multiple values of the same type.
    Size is fixed once created.

  3. Class - Blueprint used to create objects.
    Contains variables and methods together.

  4. Object - Instance of a class stored in heap memory.
    Accessed using reference variables.

  5. Interface - Defines method declarations without implementation.
    Used to achieve abstraction and multiple inheritance.

  6. Enum - Stores a fixed set of named constants.
    Used for predefined, unchangeable values

Top comments (0)