Content deleted Content added
m remove link on "Wrapper classes" (not discussed in object type) |
Sammi Brie (talk | contribs) Adding intentionally blank description, overriding Wikidata description "computer term referring to a Java class in object-oriented programming" |
||
(43 intermediate revisions by 35 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 needs 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]].
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==
The term mentioned ''Primitive Wrapper Classes'' '''does not''' mean that Wrapper classes are Primitive types in Java. It should be read this way, a class that wraps a primitive type. 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.▼
Primitive wrapper classes are not the same thing as primitive types. Whereas variables, for example, can be declared in Java as data types '''double''', '''short''', '''int''', etc., the primitive wrapper classes create instantiated objects and methods that inherit but hide the primitive data types, not like variables that are assigned the data type values.<ref name=murach/>
The <code>Byte</code>, <code>Short</code>, <code>Integer</code>, <code>Long</code>, <code>Float</code>, and <code>Double</code> wrapper classes are all [[subclasses]] 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▼
▲The <code>Byte</code>, <code>Short</code>, <code>Integer</code>, <code>Long</code>, <code>Float</code>, and <code>Double</code> wrapper classes are all [[
▲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 47 ⟶ 49:
| quote = Immutable arbitrary-precision integers.
}}</ref>
== Atomic wrapper classes ==
Line 78 ⟶ 76:
* [[Java (programming language)|Java programming language]]
* [[Java syntax]]
* [[Java compiler]]
== References ==
Line 83 ⟶ 82:
<!--Categories-->
[[Category:Java (programming language)]]
|