Primitive Data Types in JavaLast 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 Data TypeA 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 TypeIt is an 8-bit signed 2's complement integer. Its range is -128 to 127 (inclusive).
Example: 3) int Data TypeThe 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 TypeIt 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 TypeThe 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 TypeThe 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 TypeThe 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 TypeThe 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 TypeIn 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.
Key Insights on Primitive Data TypesWhy 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 TypesThere are only two main categories for Java data types: primitive and non-primitive.
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 TypesIt is especially useful in memory-constrained environments or when handling massive data, like in scientific computing or gaming engines. Wrapper Classes for Primitive TypesAll 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 UnboxingAutoboxing 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:
Always perform narrowing cautiously, especially with float, double, and long, where precision or value might be truncated. Primitive Types in ArraysWhen 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. Next TopicGraph-problems-in-java |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India