Primitive wrapper class
Encyclopedia
A primitive wrapper class in the Java programming language
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 is one of eight classes provided in the package
Java package
A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time...

 to provide object
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

 methods
Method (computer science)
In object-oriented programming, a method is a subroutine associated with a class. Methods define the behavior to be exhibited by instances of the associated class at program run time...

 for the eight primitive type
Primitive type
In computer science, primitive data type is either of the following:* a basic type is a data type provided by a programming language as a basic building block...

s. All of the primitive wrapper classes in Java are immutable
Immutable object
In object-oriented and functional programming, an immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created...

. J2SE
Java Platform, Standard Edition
Java Platform, Standard Edition or Java SE is a widely used platform for programming in the Java language. It is the Java Platform used to deploy portable applications for general use...

 5.0 introduced autoboxing of primitive types into their wrapper object, and automatic unboxing of the wrapper objects into their primitive value—the implicit conversion between the wrapper objects and primitive values.

Wrapper classes
Object type
In computer science, an object type is a datatype which is used in object-oriented programming to wrap a non-object type to make it look like a dynamic object....

 are used to represent primitive values when an is required. The wrapper classes are used extensively with classes in the package and with the classes in the reflection
Reflection (computer science)
In computer science, reflection is the process by which a computer program can observe and modify its own structure and behavior at runtime....

 package.

The primitive wrapper classes and their corresponding primitive types are:
Primitive type Wrapper class Constructor Arguments
byte byte or String
short short or String
int int or String
long long or String
float float, double or String
double double or String
char char
boolean boolean or String


The Byte, Short, Integer, Long, Float, and Double wrapper classes are all subclasses of the class.

Void

Although it is not a wrapper class, the class is similar in that it provides an object representation of the void
Void type
The void type, in several programming languages derived from C and Algol68, is the type for the result of a function that returns normally, but does not provide a result value to its caller. Usually such functions are called for their side effects, such as performing some task or writing to their...

 return. The Void class is an uninstantiable placeholder class used by the API
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...

 to hold a reference to the object representing the Java keyword void..

Atomic wrapper classes

With Java 5.0, additional wrapper classes were introduced in the package. These classes are mutable and cannot be used as a replacement for the regular wrapper classes. Instead, they provide atomic operations for addition, increment and assignment.

The atomic wrapper classes and their corresponding types are:
Primitive type Wrapper class
int
long
boolean
V


The AtomicInteger and AtomicLong classes are subclasses of the Number class. The AtomicReference class accepts the type parameter
TypeParameter
In computer programming languages, TypeParameter is a frequently-used generic label used in templates to reference an unknown data type, data structure, or class. Templates are most frequently used in Java and C++. TypeParameter is similar to a metasyntactic variable , but distinct...

 V that specifies the type of the object reference
Reference (computer science)
In computer science, a reference is a value that enables a program to indirectly access a particular data item, such as a variable or a record, in the computer's memory or in some other storage device. The reference is said to refer to the data item, and accessing those data is called...

. (See "Generics in Java
Generics in Java
Generics are a facility of generic programming that was added to the Java programming language in 2004 as part of J2SE 5.0. They allow "a type or method to operate on objects of various types while providing compile-time type safety." A common use of this feature is when using a Java Collection...

" for a description of type parameters in Java).

See also

  • java.lang
  • java.lang.reflect
  • Java programming language
    Java (programming language)
    Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

  • Java syntax
    Java syntax
    The syntax of the Java programming language is a set of rules which defines how a Java program is written and interpreted.The syntax is mostly derived from C and C++. Unlike C++, Java is almost exclusively an object-oriented language. There are no global functions or variables, all code belongs to...

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK