Java Primitive Data Type

Java Primitive Data Types

What is Java Primitive Data Type?

Java primitive data type are the basic data types that are built-in to the Java programming language. There are eight primitive data types in Java, including byte, short, int, long, float, double, char, and boolean.

These data types are used to store simple values, such as numbers and characters, and are not objects.

To understand the more about Java Primitive Data Type, Read the Complete Article.

How many Primitive Data Type In Java ?

  • There are eight primitive data types in Java:
    • byte: The byte data type is an 8-bit signed two’s complement integer, with a minimum value of -128 and a maximum value of 127. It is used when you need to store small integers.
    • short: The short data type is a 16-bit signed two’s complement integer, with a minimum value of -32,768 and a maximum value of 32,767. It is used when you need to store integers that are larger than bytes but smaller than integers.
    • int: The int data type is a 32-bit signed two’s complement integer, with a minimum value of -2^31 and a maximum value of 2^31-1. It is used when you need to store integers that are larger than shorts.
    • long: The long data type is a 64-bit signed two’s complement integer, with a minimum value of -2^63 and a maximum value of 2^63-1. It is used when you need to store integers that are larger than ints.
    • float: The float data type is a single-precision 32-bit IEEE 754 floating-point, which is used when you need to store decimal values with a relatively low precision.
    • double: The double data type is a double-precision 64-bit IEEE 754 floating-point, which is used when you need to store decimal values with high precision.
    • boolean: The boolean data type represents a single bit of information and can only have two possible values: true or false. It is used when you need to store a binary value.
    • char: The char data type is a 16-bit Unicode character, which can represent any character from the Unicode character set. It is used when you need to store characters such as letters, digits, and symbols.
Primitive Data Types in Java

Some important notes about each of the Java primitive data types:

Difference between primitive and non primitive data types in Java?

  • The main differences between primitive and non-primitive data types in Java are as follows:
    • Memory allocation: Primitive data types are stored in the stack memory, while non-primitive data types are stored in the heap memory.
    • Initialization: Primitive data types are automatically initialized with default values when they are declared, while non-primitive data types must be initialized explicitly.
    • Default values: Primitive data types have default values, which are zero or false for numeric and boolean types, respectively, while non-primitive data types have a default value of null.
    • Size: Primitive data types have a fixed size, which depends on the type, while non-primitive data types can have varying sizes, depending on the data they are storing.

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription