Primitive wrapper class in Java: Difference between revisions

Content deleted Content added
No edit summary
Tags: Mobile edit Mobile web edit
Adding intentionally blank description, overriding Wikidata description "computer term referring to a Java class in object-oriented programming"
 
(6 intermediate revisions by 5 users not shown)
Line 1:
{{Short description|none}}
In [[object-oriented programming]], a '''wrapper class''' is a [[class (computer programming)|class]] that [[Encapsulation (computer programming)|encapsulates]] [[data type|types]], so that those types can be used to create [[object (computer science)|object]] [[instance (computer science)|instances]] and [[method (computer programming)|methods]] in another class that needneeds those types. So a '''primitive wrapper class''' is a wrapper class that encapsulates, hides or ''wraps'' data types from the eight [[primitive data type]]s,<ref>S. J. Chapman, ''Introduction to Java'', Prentice Hall, 1999.</ref> so that these can be used to create instantiated objects with methods in another class or in other classes.<ref name=murach>J. Murach, ''Murach's Java Programming'', 4th Edition, Mike Murach and Associates, Inc., 2011.</ref><ref>J. R. Hubbard, ''Programming with Java'', Schaum's Outline Series/McGraw Hill, 1998.</ref> The primitive wrapper classes are found in the [[Java API]].
 
0 Primitive wrapper classes are used to create an {{Javadoc:SE|java/lang|Object}} that needs to represent primitive types in {{Javadoc:SE|java/util|Collection}} classes (i.e., in the Java API), in the {{Javadoc:SE|package=java.util|java/util}} package and in the {{Javadoc:SE|package=java.lang.reflect|java/lang/reflect}} [[Reflection (computer science)|reflection]] package. 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.,<ref name=murach/> but arrays store primitive data types while collections actually store objects.
 
The primitive wrapper classes and their corresponding primitive types are:
Line 33 ⟶ 34:
The <code>Byte</code>, <code>Short</code>, <code>Integer</code>, <code>Long</code>, <code>Float</code>, and <code>Double</code> wrapper classes are all [[subclass (computer science)|subclass]]es of the {{Javadoc:SE|java/lang|Number}} class.
 
The wrapper classes <code>BigDecimal</code> and <code>BigInteger </code> are not one of the primitive wrapper classes but are immutable.<ref>{{cite web
| url = http://www.javaranch.com/journal/2003/04/immutable.htm
| title = Mutable and Immutable Objects: Which classes are Immutable?
Line 68 ⟶ 69:
 
The <code>AtomicInteger</code> and <code>AtomicLong</code> classes are subclasses of the <code>Number</code> class. The <code>AtomicReference</code> class accepts the [[TypeParameter|type parameter]] <code>V</code> that specifies the type of the object [[reference (computer science)|reference]]. (See "[[Generics in Java]]" for a description of type parameters in Java).
<code>V</code>
 
== See also ==