Primitive Data Types in Java

Last Updated : 16 Jan 2026

In Java, primitive data types are predefined and designated as reserved keywords. It does not share a state with other primitive values. Java supports the following eight primitive data types.

To read more Data Types in Java

  1. boolean
  2. byte
  3. int
  4. long
  5. float
  6. double
  7. char
  8. short

1) boolean Data Type

A boolean data type can have two types of values, which are true and false. It is used to add a simple flag that displays true/false conditions. It represents one bit of information. It's is not a specific size data type. So, we can not precisely define its size.

Example:

2) byte Data Type

It is an 8-bit signed 2's complement integer. Its range is -128 to 127 (inclusive).

  • It is useful for saving memory in large Arrays.
  • It can be used instead of int to clarify our code using its limits.
  • It saves memory, too, because it is 4 times smaller than an integer.

Example:

3) int Data Type

The int stands for Integer. It is a 32-bit signed two's complement integer. Its range is between -231 to 231-1, which is -32,768 to 32,767 (inclusive). Its default value is 0.

If memory saving is not our primary goal, then the int data type is used to define the integer value.

Example:

4) long Data Type

It is a 64-bit 2's complement integer. Its values lie between -263 to 263-1 (inclusive). It is used for the higher values that the int data type cannot handle. Its default value is 0L.

Example:

5) float Data Type

The float data type is used to declare the floating values (fractional numbers). It is a single-precision 32-bit IEEE 754 floating-point data type. Its range is infinite. While declaring a floating point, we must end the value with an f or F.

It is useful for saving memory in large arrays of floating-point numbers. It is recommended to use the float data type instead of double while saving the floating numbers in large arrays, and not use it with precise numbers such as currency.

Example:

Note: A Scientific number can also be used to represent a scientific number with the power of 'e', where e represents the power of 10. For example, float f1= 25e2f; double d1= 15E2d; etc.

6) double Data Type

The double data type is also used for the floating-point (fractional values) number. It is similar to the float data type. Generally, it is used for decimal values. Like the float data type, its range is infinite and cannot be used for precise values such as currency. It occupies 64-bit in memory.

The default value of the double data type is 0.0d. While declaring the double-type values, we must end the value with a d.

Example:

7) char Data Type

The char data type is used to declare a character type. It is a single 16-bit Unicode Character range from 0 to 65,535 (inclusive).

While declaring a character variable, its value must be surrounded by a single quote ('').

Example:

Note: The ASCII character values can also be used to display the characters.

8) short Data Type

The short data type is also used to store integer values. It is a 16-bits signed 2's complement range from -32,768 to 32,767 (inclusive). It is also used to save memory, just like the byte data type.

It is recommended to use the short data type in a large array when memory saving is essential.

Default Values and Size of Primitive Data Type

In Java, it is not necessary to assign values while declaring. Every data type has some default values. If we do not assign a value to a data type, the JVM automatically assign the default value to it.

Mostly, these values are null or 0 (Zero), depending on the data type. However, it is not recommended to leave the variables to their default values. If you have declared a variable, then initialize it with some value. Otherwise, do not declare it unnecessarily.

Data typeSizeDefault ValueRange/ Description
boolean1-bitfalseTrue Or False Only
byte8-bit0Very Small Integer (-128 to 127)
int32-bit0Standard Integer (-2³¹ to 2³¹-1)
long64-bit0LLarge Integer (-2⁶³ to 2⁶³-1)
float32-bit0.0fDecimal Values (Single-Precision)
double64-bit0.0dDecimal Values (Double-Precision)
char16-bit'\u0000'Single Unicode Character
short16-bit0Small Integer (-32,768 to 32,767)

Key Insights on Primitive Data Types

Why Primitive Data Types?

All fundamental data is stored in Java as these primitive types. Because computer registers are objects in their own right, they store data without taking much time. Java utilizes variables to label simple things like numbers, letters, and conditions that are either true or false.

If we need to process data in a range of problems or perform math on large amounts, using the basic types is best. For instance, replacing Integer with int will conserve memory and prevent the time and effort spent creating and disposing of objects.

Primitive Data Types Vs. Non-Primitive Data Types

There are only two main categories for Java data types: primitive and non-primitive.

  • int, byte, short, long, float, double, char, and boolean are all primitive types included by default. These variables are used to keep values.
  • A non-primitive type refers to groups of objects such as String, Array, or various custom classes. They save the memory address of the location where the information is properly saved.

Knowing this difference is needed because primitives perform better, use less memory, and let you save space by not needing methods or handling nullability, while objects provide more range and can take part in method calls.

Memory Consumption of Primitive Types

It is especially useful in memory-constrained environments or when handling massive data, like in scientific computing or gaming engines.

Wrapper Classes for Primitive Types

All the wrapper classes of primitive type, such as Integer, Double, Character, etc., belong to java.lang package.

Thanks to wrapper classes, primitive types can be applied in places that call for objects, for example, in lists (List<Integer>), synchronization, and with overloading. They also include utility methods. For example,

Using wrapper classes bridges the gap between simple data and Java's object-oriented features.

Autoboxing and Unboxing

Autoboxing is the automatic conversion of a primitive to its corresponding wrapper class. Unboxing is the reverse.

This feature improves code readability and simplifies working with collections, but developers must be aware of the performance cost due to hidden object creation.

Type Casting and Conversion

Java supports two types of type casting between primitives:

  • Widening (Implicit): Automatically converts a smaller type to a larger type.
  • Narrowing (Explicit): Converts a larger type to a smaller type but may cause data loss.

Always perform narrowing cautiously, especially with float, double, and long, where precision or value might be truncated.

Primitive Types in Arrays

When performance and how much memory is taken by code are important, use int[] or char[] instead of Integer[] or Character[] arrays. For example,

Most algorithms, simulations, and real-time systems rely on arrays for their certain and efficient behavior.