Java Primitive Types, Ranges and Wrapper Classes (ISC Class 11 Computer Science)
Updated 17 October 2026 · Fact-checked
Java has eight primitive types: byte (8 bits), short (16), int (32), long (64), float (32), double (64), char (16) and boolean. A signed n-bit integer ranges from -2^(n-1) to 2^(n-1) - 1; going beyond the range wraps around (overflow). Each primitive has a wrapper class (Integer, Double, Character, Boolean, and so on) that turns it into an object and offers methods such as parseInt(); converting between them is autoboxing and unboxing.
A byte holds -128 to 127; adding 1 to the maximum 127 wraps round to the minimum -128, which is overflow.
Illustration drawn for QuestionBuddy.
Understand Primitive Data Types, Ranges, Overflow and Wrapper Classes
Primitive types.
| Type | Size | Range / values | Default |
|---|---|---|---|
| byte | 8 bits | -128 to 127 | 0 |
| short | 16 bits | -32,768 to 32,767 | 0 |
| int | 32 bits | -2,147,483,648 to 2,147,483,647 | 0 |
| long | 64 bits | -2^63 to 2^63 - 1 | 0L |
| float | 32 bits | about 7 digits of precision | 0.0f |
| double | 64 bits | about 15 digits of precision | 0.0 |
| char | 16 bits | 0 to 65,535 (Unicode) | '\u0000' |
| boolean | 1 bit of information | true or false | false |
For a signed n-bit integer: minimum = -2^(n-1), maximum = 2^(n-1) - 1.
Overflow. A value beyond the range wraps around: byte b = 127; b++; gives -128. int max + 1 gives -2,147,483,648.
Literals. 10L (long), 3.5f (float), 3.5 (double), 'A' (char), true.
Wrapper classes. Integer, Double, Character, Boolean, Byte, Short, Long, Float: objects that hold a primitive value; needed where objects are required (collections) and for utility methods.
int a = Integer.parseInt("25"); // String to int: 25
double d = Double.parseDouble("3.5"); // 3.5
Integer x = Integer.valueOf(7); // boxing
int y = x.intValue(); // unboxing
String s = Integer.toString(45); // "45"Constants: Integer.MAX_VALUE, Integer.MIN_VALUE. Character: isDigit(), isLetter(), isUpperCase(), toLowerCase(). *Autoboxing:* automatic primitive to wrapper (Integer p = 5;). *Unboxing:* wrapper to primitive (int q = p;).
Class as type. A class is a user-defined data type: Student s = new Student(); s holds a reference to an object, not the object itself.
Primitive Data Types, Ranges, Overflow and Wrapper Classes: key facts
- Range of a signed integer
- Minimum = -2^(n-1)
- Maximum = 2^(n-1) - 1
- n = number of bits
- byte: -128 to 127.
- Overflow
- Maximum + 1 wraps to the minimum | Minimum - 1 wraps to the maximum
- No error is reported.
- Conversion methods
Integer.parseInt String Double.parseDouble String Integer.toString int valueOf() - Wrapper utilities.
How to answer Primitive Data Types, Ranges, Overflow and Wrapper Classes questions
Check the type and its range before computing.
- 1Write the type of every variable.
- 2Check whether a value fits the range (use 2^(n-1) - 1).
- 3Apply the wrapper method on the correct string or value.
- 4Trace the result, noting wrap-around.
Primitive Data Types, Ranges, Overflow and Wrapper Classes in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Overflow
Suppose a counter stored in a byte variable counts items from 120 upwards and adds 10.
What value does it hold?
Try it first, then show the solutionSolution
- The maximum byte value is 127.
- 120 + 10 = 130, which wraps to 130 - 256 = -126.
Answer: -126 (a nonsense negative count).
Memory hook: Beyond the top, it wraps to the bottom.
Tricks to remember Primitive Data Types, Ranges, Overflow and Wrapper Classes
Short memory aids. Say each one aloud once, then use it on a question the same day.
8-16-32-64
byte, short, int, long sizes.
Use it when: Integer types.
Half up, half down
Signed range: minus 2^(n-1) to 2^(n-1) minus 1.
Use it when: Range.
parse reads, toString writes
parseInt converts text to number; toString the reverse.
Use it when: Wrapper.
Primitive Data Types, Ranges, Overflow and Wrapper Classes: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Size · 1 mark · MCQBoard level
The size of a Java int is:
(a) 8 bits (b) 16 bits (c) 32 bits (d) 64 bits
Try it first, then show the solutionSolution
- int is 32 bits.
Answer: (c) 32 bits
Example 2: Wrapper methods · 5 marks · Short answerBoard level
Give the output: System.out.println(Integer.parseInt("25") + 5); System.out.println(Double.parseDouble("3.5") * 2); System.out.println(Integer.toString(45).length()); System.out.println(Character.isLetter('x')); System.out.println(Integer.valueOf(7).doubleValue()); (5 marks)
Try it first, then show the solutionSolution
- 25 + 5 = 30.
- 3.5 x 2 = 7.0.
- "45" has 2 characters.
- Character.isLetter('x') is true.
- 7 as a double is 7.0.
Answer: 30
7.0
2
true
7.0
Example 3: Overflow · 5 marks · Short answerHarder board level
Find the output: byte b = 127; b++; System.out.println(b); int m = Integer.MAX_VALUE; m = m + 1; System.out.println(m); short s = 32767; s++; System.out.println(s); and state the range of a byte using the formula. (5 marks)
Try it first, then show the solutionSolution
- byte range: -2^7 to 2^7 - 1 = -128 to 127; 127 + 1 wraps to -128.
- int max is 2,147,483,647; adding 1 gives -2,147,483,648.
- short max is 32,767; adding 1 gives -32,768.
Answer: -128
-2147483648
-32768
Example 4: Size and range · 4 marks · Short answerHarder board level
Find (i) the number of values a 16-bit signed integer can hold and its range; (ii) the largest value of an 8-bit unsigned value (for comparison); (iii) whether 40000 can be stored in a short and in an int. (4 marks)
Try it first, then show the solutionSolution
- (i) 2^16 = 65,536 values; range -32,768 to 32,767.
- (ii) unsigned 8-bit: 0 to 255 (2^8 - 1).
- (iii) 40,000 > 32,767 so it does not fit a short; it fits an int.
Answer: (i) 65,536 values, -32,768 to 32,767; (ii) 255; (iii) not in a short, yes in an int.
Example 5: Boxing and unboxing · 4 marks · Short answerHOTS / competency
Explain autoboxing and unboxing with the statements Integer p = 5; int q = p + 3; Integer r = q; and give the values. Why can an Integer be null but an int cannot? (4 marks)
Try it first, then show the solutionSolution
- Integer p = 5: autoboxing (int to Integer).
- p + 3: p is unboxed to int; q = 8.
- Integer r = q: autoboxing again; r holds 8.
- An Integer is an object reference and can be null (no object); an int is a value that always exists.
Answer: Autoboxing converts int to Integer automatically; unboxing converts back. p = 5, q = 8, r = 8. An Integer variable can be null because it is a reference; an int cannot.
Where students lose marks in Primitive Data Types, Ranges, Overflow and Wrapper Classes
The slips examiners see most often, and what to write instead.
Mistake: Saying byte ranges from 0 to 255
Unsigned thinking.
Wrong working
0 to 255
Right working
-128 to 127
Do this: Java integers are signed.
Usually costs: 1-2 marks.
Mistake: Expecting an error on overflow
Other languages.
Wrong working
ArithmeticException on max + 1
Right working
Silent wrap-around
Do this: No exception is thrown.
Usually costs: 1 mark.
Mistake: Using parseInt on a number
Wrong type.
Wrong working
Integer.parseInt(25)
Right working
Integer.parseInt("25")
Do this: It takes a String.
Usually costs: 1-2 marks.
Exam tips
- Give the formula for the range when writing ranges.
- Show wrap-around as a calculation.
- Name the wrapper class of each primitive.
Practice questions on Primitive Data Types, Ranges, Overflow and Wrapper Classes
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
Which of the following is a wrapper class?
(a) int (b) Integer (c) integer (d) IntHint
Capital letter and a class.
Answer
(b) Integer
Q2 · 2 marks · Short answerBoard level
Write the wrapper class of each primitive type: byte, short, int, long, float, double, char, boolean. (2 marks)
Hint
Capitalise or expand.
Answer
Byte, Short, Integer, Long, Float, Double, Character, Boolean.
Q3 · 3 marks · Short answerHarder board level
Find the output: int a = Integer.parseInt("12") * 2; String t = Integer.toString(a) + 5; System.out.println(a + " " + t + " " + t.length()); (3 marks)
Hint
"24" + 5.
Answer
a = 24; t = "24" + 5 = "245"; t.length() = 3. Output: 24 245 3
Q4 · 4 marks · Short answerHarder board level
A long variable holds 3,000,000,000. Show whether it fits an int, and the result of (int) of it: use 2^32 = 4,294,967,296. (4 marks)
Hint
Larger than 2,147,483,647.
Answer
3,000,000,000 > 2,147,483,647, so it does not fit an int. (int) 3,000,000,000L = 3,000,000,000 - 4,294,967,296 = -1,294,967,296.
Q5 · 3 marks · Short answerHOTS / competency
A hospital program stores the number of patients in a byte. On a busy day 200 patients are counted using byte n = (byte) 200; Give the value stored, explain the risk and recommend the type. (3 marks)
Hint
200 - 256.
Answer
(byte) 200 = 200 - 256 = -56, a negative count. Use short or int, which can hold the counts without wrap-around.
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.int size?Show answer
32 bits.
2.byte range?Show answer
-128 to 127.
3.Wrapper of char?Show answer
Character.
4.Autoboxing?Show answer
Primitive to wrapper automatically.
5.Default of boolean?Show answer
false.
Primitive Data Types, Ranges, Overflow and Wrapper Classes: frequently asked questions
Is String a primitive?
No, it is a class.
What does Integer.MAX_VALUE give?
2,147,483,647.
Are wrappers immutable?
Yes.
What is float precision?
About 7 digits.