Content deleted Content added
Wrapper classes aren't specifically restrained only to Java |
Sammi Brie (talk | contribs) Adding intentionally blank description, overriding Wikidata description "computer term referring to a Java class in object-oriented programming" |
||
(20 intermediate revisions by 18 users not shown) | |||
Line 1:
{{Short description|none}}
In [[object
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
The primitive wrapper classes and their corresponding primitive types are:
:{| class="wikitable"
! Primitive type !! Wrapper class !! Constructor
|-
| <code>byte</code> || {{Javadoc:SE|java/lang|Byte}} || <code>byte</code> or <code>String </code>
Line 25 ⟶ 26:
|}
==The difference between wrapper classes and primitive types==
Primitive wrapper classes are not the same thing as
▲Primitive wrapper classes are not the same thing as are primitive types. The main difference is that whereas variables can be declared in Java as '''double''', '''short''', '''int''', or '''char''', etc., data types, the eight primitive wrapper classes create instantiated objects and methods that inherit but hide the eight primitive data types, not variables that are assigned data type values.<ref>J. Murach, ''Murach's Java Programming'', 4th Edition, Mike Murach and Associates, Inc., 2011.</ref>
Therefore, the term ''Primitive wrapper class'' does not mean that wrapper classes are primitive types. It should be understood to be a class that wraps primitive types. Wrapper classes can be used to store the same value as of a primitive type variable but the instances/objects of wrapper classes themselves are ''Non-Primitive''. We cannot say that Wrapper classes themselves are Primitive types. They just wrap the primitive types.
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
| url = http://www.javaranch.com/journal/2003/04/immutable.htm
| title = Mutable and Immutable Objects: Which classes are Immutable?
| author = David O'Meara
| date = April 2003
| publisher = Java Ranch
| accessdate = 2012-05-14
Line 51 ⟶ 49:
| quote = Immutable arbitrary-precision integers.
}}</ref>
== Atomic wrapper classes ==
Line 77 ⟶ 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).
== See also ==
|