computer term referring to a Java class in object-oriented programming
In object-oriented programming, a wrapper class is a class that encapsulates types, so that those types can be used to create object instances and methods in another class that needs those types. โ€ฆ Wikipedia
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Primitive_wrapper_class_in_Java
Primitive wrapper class in Java - Wikipedia
March 7, 2026 - Collection classes are Java API-defined classes that can store objects in a manner similar to how data structures like arrays store primitive data types like int, double, long or char, etc., but arrays store primitive data types while collections actually store objects. The primitive wrapper classes and their corresponding primitive types are: Primitive wrapper classes are not the same thing as primitive types. Whereas variables, for example...
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_wrapper_classes.asp
Java Wrapper Classes
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... Wrapper classes provide a way to use primitive data types (int, boolean, etc..) as objects.
Discussions

Why use Wrapper Classes over Primitive Datatypes?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
๐ŸŒ r/javahelp
5
4
February 4, 2023
integer - What is the real difference between primitives and wrapper classes in Java - Stack Overflow
However, not able to understand the real difference between primitives and wrapper classes. Why there was a need to create two different ways to hold the data? Why we did not reuse what was already available? For example, if wrapper classes were introduced before primitives then why we did ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Wrapper Classes Discussion
Read Effective Java 3rd Edition by Joshua Bloch, Item 68 for a full discussion. Joshua recommends to prefer primitives over boxed primitives. A few points he makes: *Primitives are more time and space-efficient. *Double equals operator can't be used with Boxed primitives. *Unboxing can result in a NPE. Auto-unboxing happens automatically, for example, when primitives and boxed primitives are mixed in an operation. More on reddit.com
๐ŸŒ r/learnjava
11
8
September 20, 2022
Everything in JavaScript is an object...what about primitive data types?
Primitives are not objects. When you call a method on them they are temporarily wrapped in an object and unwrapped when the method is executed. More on reddit.com
๐ŸŒ r/learnjavascript
36
58
June 11, 2022
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ wrapper-classes-java
Wrapper Classes in Java - GeeksforGeeks
Java provides wrapper classes for all eight primitive data types to support object-based operations. Example: Converting Primitive to Wrapper (Autoboxing)
Published ย  April 6, 2026
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ wrapper-class-vs-primitive-data-types-in-java-with-io
Wrapper Class vs Primitive Data Types in Java with I/O - GeeksforGeeks
November 21, 2025 - Usage in Java Collections (e.g., ArrayList<Integer>) ... Below are clean and real-world I/O programs that show where primitives and wrapper classes differ. Example 1: Reading Primitive Values Using Scanner (I/O)
๐ŸŒ
Reddit
reddit.com โ€บ r/javahelp โ€บ why use wrapper classes over primitive datatypes?
r/javahelp on Reddit: Why use Wrapper Classes over Primitive Datatypes?
February 4, 2023 -

I just started my APCSA course and am slightly confused on why a person might user Wrapper Classes instead of the more simple primitive data types.

Could someone give an example of a situation where you would want to use primitives and one where you should use a Wrapper class?

Top answer
1 of 5
4
You use wrapper classes when you either need a nullable value or when you can't use a primitive value for other reasons, like when storing the value in an Object variable or when using generics (due to type erasure). Generics are probably the most common usecase for wrapper classes, think something like List. You want to use primitives in most other cases as they're way more efficient.
2 of 5
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
๐ŸŒ
DEV Community
dev.to โ€บ abhishek_kumar_d9009a7ae6 โ€บ primitive-types-vs-wrapper-classes-2cf0
Primitive Types vs. Wrapper Classes - DEV Community
October 2, 2024 - Java provides a wrapper class for each primitive type. ... Autoboxing and Unboxing refer to the automatic conversion between primitive types and their corresponding wrapper classes. The process of automatically converting a primitive type into its corresponding wrapper class when needed. Happens, for instance, when you try to add a primitive type to a collection (like ArrayList) that requires objects.
๐ŸŒ
Medium
medium.com โ€บ @bpnorlander โ€บ java-understanding-primitive-types-and-wrapper-objects-a6798fb2afe9
Java: Understanding Primitive Types and Wrapper Objects | by Brian Norlander | Medium
March 19, 2019 - +-----------+---------------+ | Data Type | Default Value | +-----------+---------------+ | byte | 0 | | short | 0 | | int | 0 | | long | 0L | | float | 0.0f | | double | 0.0d | | boolean | false | | char | '\u0000' | +-----------+---------------+ A ...
Find elsewhere
Top answer
1 of 3
16

The real difference is that primitive types are not reference types.

In Java type system, reference types have a common root, while primitive types do not: All reference types are subtypes of Object. In comparison, primitive types do not have a common root; each primitive type is its own special unicorn.

This means that a variable declared with Object type can hold a value of any reference type, but it cannot hold a value of any primitive type.

This is a problem if you want to create data structures that are generally useful. Consider how you would implement a "dynamic array" data structure like ArrayList or Vector. You could use an array Object[] to store the elements, and that would work for all reference types. But since primitive types don't have a common root you would have to create a separate implementation for each primitive type.

To solve this problem, wrapper classes were created. Now, instead of needing 8 separate implementations of dynamic array (1 for reference types and 7 for primitive types), you could wrap each primitive value in an object, and just use the implementation for reference types.

Primitive types and wrapper classes were created at the same time, when the first design and implementation of Java 1.0 were made. The designers did not "reuse what was already available" because nothing was available: they built everything from scratch.

Could the designers have solved the problem some other way, maybe by creating a type system that had a common root for both primitive and reference types? Yes, but they didn't, and they probably had good reasons: implementation complexity, ease of understanding, time to market, ...

2 of 3
5

Actually, this question is pretty insightful. The answers are good and correct, but the underlying question that I think is worth asking is: should primitive types exist at all? We had a lot of discussion about this at the time and I think the reason things ended up the way they did had to do with the fact that Oak (later Java) was designed as an embedded language for the IOT (internet of things). If it had been originally designed as a server language, it might have been very different. I think primitive types are a legacy idea that is actually very harmful for exactly the reasons that Joni mentions. It's possible and desirable to have everything in the system extend Object.

How could you eliminate primitives? With a smarter JVM. HotSpot could turn special primitive objects into appropriate machine code wherever possible and there wouldn't be a need for autoboxing, wrappers or difficulties with the type system being split. The only limitation that I think would need to be placed on Integer, Float, Double, etc., is that they would have to be final. This would allow these classes to be optimized anywhere possible as if they were primitives without actually having primitives in the language. You could even have syntactic abbreviations like 'int', 'float' and 'double' for these special classes, but the important thing is that the type system would be better if it was fully unified.

But you don't start trying to build such a thing when you're thinking about smart toasters. What happened to Java in terms of its wild success was a pure accident. It happened to be a solution to a lot of web-related issues just sitting there at the right time. But it wasn't planned that way, so there are a lot of things people would like to have back. I think a lot of people at Sun/Oracle would eliminate primitives in hindsight.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java-i-o-operation-wrapper-class-vs-primitive-class-variables
Java I/O Operation โ€“ Wrapper Class vs Primitive Class Variables | GeeksforGeeks
November 15, 2022 - When we create an object to a wrapper class, it contains a field and in this field, we can store primitive data types. In other words, we can wrap a primitive value into a wrapper class object. Methods: We can use two ways to ... Prerequisite :- Local inner classes , anonymous inner classes 1) What is the output of the following java program?
๐ŸŒ
Quora
quora.com โ€บ What-is-the-difference-between-primitive-data-type-and-type-wrapper-class-What-are-some-examples
What is the difference between primitive data type and type wrapper class? What are some examples? - Quora
That being the case, there is sometimes ... are wrapper classes which, well, wrap the primitive value in an object (e.g. an int within an Integer). Starting with Java 5, this became more โ€œbehind the scenesโ€ in which Java would auto box and auto unbox primitives. (Example: You can add an int to a List of Integers without first explicitly creating the Integer object and sticking the int in it.) ... A primitive type is a predefined data type provided ...
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2017 โ€บ 09 โ€บ wrapper-class-in-java
Wrapper class in Java
November 8, 2022 - We can also create a custom wrapper class to wrap a primitive type to an object. Here, we have a int data type that belongs to class XYZ. We can use this primitive data type as object using the constructor and getter setter methods of XYZ class as shown below:
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ java basics โ€บ data types
Java Data Types - Primitive and Wrapper Types with Examples
December 27, 2022 - For example, java.lang.Integer class is the object version of int data type. Similarly, we have a total of 8 wrapper classes for all 8 primitive data types.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ java โ€บ wrapper classes in java
Wrapper Classes in Java - Scaler Topics
April 27, 2024 - We can also create a custom Wrapper class in Java, which wraps a primitive data type. ... A: An example of a wrapper in Java is the Integer class, which wraps the primitive data type int to provide additional functionality.
๐ŸŒ
Medium
medium.com โ€บ @quipoin04 โ€บ wrapper-classes-in-java-complete-guide-with-examples-150b77f47797
Wrapper Classes in Java โ€” Complete Guide with Examples | by Quipoin | Medium
October 7, 2025 - Wrapper Classes in Java โ€” Complete Guide with Examples In Java, primitive data types (like int, char, double) are fast and memory-efficient, but they are not objects. However, many features in Java โ€ฆ
๐ŸŒ
Medium
medium.com โ€บ javarevisited โ€บ java-basics-primitive-data-types-and-wrapper-classes-made-simple-d73072ed3586
Java Journeys : Primitive Data Types and Wrapper Classes Made Simple | by Ritu Sitlani | Javarevisited | Medium
March 12, 2024 - The wrapper classes are: Integer, Double, Boolean, etc., with each corresponding to a primitive data type. Wrapper classes in Java bridge the gap between primitive data types and objects, making it easy to use primitives where objects are needed.
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ wrapper
Java Wrapper Class (With Examples)
In Java, sometimes we might need to use objects instead of primitive data types. For example, while working with collections. // error ArrayList<int> list = new ArrayList<>(); // runs perfectly ArrayList<Integer> list = new ArrayList<>(); In such cases, wrapper classes help us to use primitive ...
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ core java โ€บ wrapper classes in java
Wrapper Classes in Java | Baeldung
March 17, 2024 - Well, we can either use constructor or static factory methods to convert a primitive value to an object of a wrapper class. As of Java 9, however, constructors for many boxed primitives such as Integer or Long have been deprecated. So itโ€™s highly recommended to only use the factory methods on new code. Letโ€™s see an example of converting an int value to an Integer object in Java:
๐ŸŒ
Study.com
study.com โ€บ business courses โ€บ java programming tutorial & training
Wrapper Classes in Java: Definition & Example - Lesson | Study.com
January 5, 2018 - Next, we instantiated (created) a new instance of the Integer class and gave it the value of the primitive variable. To unlock this lesson you must be a Study.com member Create an account ยท A really cool feature of the wrapper classes is that ...
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ java_wrapper_classes.htm
Java - Wrapper Classes
And the Wrapper object will be converted back to a primitive data type, and this process is called unboxing. The Number class is part of the java.lang package.