bscodinglab

Data Types

Data types specify the type of data that a variable can store. Java supports several primitive data types, including int, float, double, char, boolean, etc. These are used to store simple values. Additionally, Java supports reference data types, such as arrays, objects, and classes.

There are two types of data types in Java
Data TypeName of Data TypeDescription
Primitiveint, float, char, booleanHolds a single value of a specific type
Non-primitiveString, Object,Array,ClassHolds a collection of values or objects
  1. Primitive Data types :- Primitive data types are the basic building blocks of data manipulation in Java. They are eight in number:
    1. boolean – A boolean value can be either trueor false.
    2. byte – A byte value can store an integer from -128 to 127.
    3. short – A short value can store an integer from -32,768 to 32,767.
    4. int – An int value can store an integer from -2,147,483,648 to 2,147,483,647.
    5. long – A long value can store an integer from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
    6. float – A float value can store a floating-point number with 6 to 7 decimal digits of precision.
    7. double – A double value can store a floating-point number with 15 to 16 decimal digits of precision.
    8. char – A char value can store a single character.
  1. Non-Primitive :- Non-primitive data types are more complex data types that are built on top of the primitive data types. They include:
    1. Interfaces:-An interface in Java is a reference type that defines a set of methods that a class must implement.
    2. String – A String is a sequence of characters.
    3. Arrays – An Array is a collection of objects of the same type.
    4. Classes – A Class is a blueprint for creating objects.