Quick revision
The short answer
Java has eight primitive types: byte (8 bits), short (16), int (32), long (64), float (32), double (64), char (16) and boolean. Fields get default values of 0, 0.0, '\u0000' or false, while local variables get no default at all. The size of boolean is left to the JVM because it only needs to hold true or false, and char is an unsigned 16-bit type that runs from 0 to 65535.
What to remember
In this answer, we went through Java's eight primitive types and their fixed sizes: byte, short, int and long at 8, 16, 32 and 64 bits in two's complement, float and double at 32 and 64 bits in IEEE 754, and char at 16 bits. We saw that fields start at 0, 0.0, '\u0000' or false while locals must be assigned before use, that boolean's size is left to the JVM, which treats it as an int on the stack and a byte in arrays, and that char is the only unsigned type, running from 0 to 65535.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Java has eight primitive types: byte (8 bits), short (16), int (32), long (64), float (32), double (64), char (16) and boolean. Fields get default values of 0, 0.0, '\u0000' or false, while local variables get no default at all. The size of boolean is left to the JVM because it only needs to hold true or false, and char is an unsigned 16-bit type that runs from 0 to 65535.
Why this question is asked
Primitive types are the building blocks under every Java program, and their sizes decide how much memory our data takes, where overflow happens and which conversions lose information. Interviewers ask this question to see whether we know the exact sizes rather than roughly, and whether we understand the two odd members of the family: boolean, whose size is not fixed, and char, the only unsigned one. In this answer, we will go through the eight types and their sizes, see what values fields and local variables start with, look at why boolean has no specified size, explain char's range, and see why Java fixes these sizes for every platform.
1A Quick Recap of Primitive Types
A primitive type holds a plain value directly, not a reference to an object. When we write int count = 5, the variable holds the number 5 itself. When we write Integer count = 5, the variable holds a reference to an Integer object somewhere on the heap. Primitives have no methods, cannot be null and cost no object header, which is why Java keeps them even though everything else is an object.
Java has exactly eight of them. Four are whole-number types, byte, short, int and long, and they store values in two's complement, the usual way of encoding signed integers in which the top bit carries the sign. Two are floating point types, float and double, which follow the IEEE 754 standard used by almost every processor. Then there is char for text and boolean for true or false.
| Type | Size | Range or format | Field default |
|---|---|---|---|
| byte | 8 bits | -128 to 127 | 0 |
| short | 16 bits | -32,768 to 32,767 | 0 |
| int | 32 bits | about -2.1 billion to 2.1 billion | 0 |
| long | 64 bits | about -9.2 x 10^18 to 9.2 x 10^18 | 0L |
| float | 32 bits | IEEE 754 single precision | 0.0f |
| double | 64 bits | IEEE 754 double precision | 0.0d |
| char | 16 bits | 0 to 65535, unsigned UTF-16 code unit | '\u0000' |
| boolean | not specified | true or false | false |
2Default Values: Fields Versus Local Variables
Fields and array elements are always initialised for us. When an object is created, the JVM clears its memory, so numeric fields start at 0, floating fields at 0.0, char at '\u0000' (the character with code 0), boolean at false and every reference at null. Local variables are different: they get no default, and the compiler refuses any read before a definite assignment.
The reason for the difference is cost and safety. Clearing a new object is cheap and stops us from ever seeing leftover memory. For locals, Java prefers to catch the mistake at compile time, because a forgotten assignment in a method is almost always a bug, not an intention.
3Why the Size of boolean Is Not Specified
A boolean only needs one bit of information, but no processor can address a single bit, so any real implementation has to round it up to something larger. The Java Virtual Machine Specification therefore does not give boolean a size. It only says what the JVM must do with it, and leaves the storage to the implementation.
In practice, the JVM has almost no instructions of its own for boolean. A boolean value on the operand stack, the JVM's working area for calculations, is treated as an int that holds 0 or 1. Boolean arrays are read and written with the same instructions as byte arrays, and HotSpot stores one byte per element. A boolean field in an object usually takes one byte too, although the object layout may add padding around it. So a boolean[] of a million elements takes about a megabyte, not 125 kilobytes. If we really need one bit per flag, java.util.BitSet packs 64 flags into each long.
4Char: The Only Unsigned Type
char holds a UTF-16 code unit, a 16-bit number that stands for a character or for half of one. Because a code unit is never negative, char is unsigned and runs from '\u0000' (0) to '\uffff' (65535). It is the only unsigned integral type in Java, and that shows up when we do arithmetic with it.
Notice the last two lines. Characters outside the first 65,536 code points, such as many emoji, need two char values, called a surrogate pair. So one char is not always one character, and code that walks text by char can split such characters in half. String.codePoints() walks by whole characters instead.
5Why Java Fixes the Sizes
In C, the size of int depends on the compiler and the processor: it has been 16 bits on some machines and 32 or more on others. Java chose the opposite rule. The language specification fixes every numeric size, so an int is 32 bits and overflows at exactly 2,147,483,647 on a laptop, a phone or a mainframe. This is part of what makes a compiled class file run the same everywhere. The cost is that Java cannot pick a size that suits each machine, but in practice the predictability has been worth much more.
6Follow-up questions
Why does Java have no unsigned int, and what do Integer.toUnsignedString and Integer.divideUnsigned give you?
The designers left unsigned types out to keep the language simple, because mixing signed and unsigned values is a common source of bugs in C. Since Java 8, the Integer and Long classes let us treat the same 32 or 64 bits as unsigned when we need to, for example when reading a protocol field. Integer.toUnsignedString(-1) returns "4294967295", because the bits of -1 are all ones. Integer.divideUnsigned(-2, 2) returns 2147483647, because -2 read as unsigned is 4294967294. There are also compareUnsigned, parseUnsignedInt and toUnsignedLong, so the storage stays signed while the interpretation changes.
Do primitives in a local variable take less memory than fields?
The sizes describe the range of values, not the exact storage. On the JVM's stack, small types such as byte, short, char and boolean are held in int-sized slots, and long and double take two slots. Inside objects and arrays, HotSpot does use the compact sizes, which is where the difference matters for memory.
What is the default value of a long or float field written in code?
A long field defaults to 0L and a float field to 0.0f. The suffix only matters when we write literals ourselves: 0 is an int literal, 0L a long, 0.0 a double and 0.0f a float.
7Conclusion
In this answer, we went through Java's eight primitive types and their fixed sizes: byte, short, int and long at 8, 16, 32 and 64 bits in two's complement, float and double at 32 and 64 bits in IEEE 754, and char at 16 bits. We saw that fields start at 0, 0.0, '\u0000' or false while locals must be assigned before use, that boolean's size is left to the JVM, which treats it as an int on the stack and a byte in arrays, and that char is the only unsigned type, running from 0 to 65535.
Open with
Java has eight primitives. The integer types are byte, short, int and long, at 8, 16, 32 and 64 bits, all signed two's complement. float and double are 32 and 64 bit IEEE 754 floating point numbers. char is a 16-bit unsigned UTF-16 code unit, so its range is 0 to 65535, or backslash u 0000 to backslash u ffff, and it is the only unsigned integral type.
Then, if they want more
Then there is boolean. Fields and array elements get defaults: zero for the integer types, 0.0 for float and double, the zero character for char, false for boolean and null for references.
Local variables get no default; the compiler makes me assign them before I read them. boolean has no specified size because it only carries one bit and memory cannot be addressed by bit, so the JVM specification leaves storage to the implementation.
In practice the JVM handles boolean values as ints on the operand stack, and HotSpot stores boolean arrays as one byte per element, so if I need dense flags I use a BitSet.
One more point I would add is that, unlike C, Java fixes all these sizes in the language, so int is 32 bits on every platform and overflow behaves the same everywhere. For unsigned work, Integer and Long have helpers such as toUnsignedString and divideUnsigned since Java 8.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 8
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "List Java's eight primitive types with their sizes and default field values. Why is the...": https://scrivio-interview-library.netlify.app/java/types-and-values/035c6b8190/