answersLogoWhite

0


Best Answer

In Java an integer and a double are "primitive" data types.

When dealing with functions, often you want to do more than send an "int" or a "double"'s VALE, you wish to send a REFERENCE of a number type to a function so that you can operate on that number type. What you can do is create a new Integer, Boolean, or Double, and send it to the function. This creates a "CLASS" that acts as an Integer (or whatever you chose).

Eg. You want a function that takes in a number variable, and adds two to it, and returns NOTHING. You cannot send a normal "int", because that integer cannot be "referenced" to after the function call. You would create a new Integer Object from the Integer Class, and insert that new object to the function.

Integer four = new Integer(4); // Makes a new Integer named "four" with the value 4.

There is a wrapper class for every primitive in Java. For instance, the wrapper class for int is Integer, the class for float is Float, and so on. Remember that the primitive name is simply the lowercase name of the wrapper except for char, which maps to Character, and int, which maps to Integer.

The Wrapper classes for each of the primitive types is as follows:

1. boolean - Boolean

2. byte - Byte

3. char - Character

4. double - Double

5. float - Float

6. int - Integer

7. long - Long

8. short - Short

A point to note here is that, the wrapper classes for numeric primitives have the capability to convert any valid number in string format into its corresponding primitive object. For ex: "10" can be converted into an Integer by using the below line

Integer intVal = new Integer("10");

I can do the same for all numeric types like long, short etc. But, if I pass an invalid value I will get a "NumberFormatException" Ex:

Integer intVal = new Integer("Haha");

The Wrapper Constructors

All of the wrapper classes except Character provide two constructors: one that takes a primitive of the type being constructed, and one that takes a String representation of the type being constructed-for example

Integer i1 = new Integer(42);

Integer i2 = new Integer("42");

or

Float f1 = new Float(3.14f);

Float f2 = new Float("3.14f");

The Character class provides only one constructor, which takes a char as an argument-for example

Character c1 = new Character('c');

The constructors for the Boolean wrapper take either a boolean value true or false, or a String. If the String's case-insensitive value is "true" the Boolean will be true-any other value will equate to any other value will equate to false. Until Java 5, a Boolean object couldn't be used as an expression in a boolean test-for instance

Boolean b = new Boolean("false");

if (b) // won't compile, using Java 1.4 or earlier

As of Java 5, a Boolean object can be used in a boolean test, because the compiler will automatically "unbox" the Boolean to a boolean.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are Integer Boolean and Double wrapper classes?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are object wrappers?

Wrapper classes are classes that are used to make primitive variables into objects, and to make wrapped objects into primitives. int, boolean, double are all primitive data types and their respective wrapper classes are Integer, Boolean, and Double. Wrapper classes are useful in storing primitive data types in higher level data structures such as Stack<Object>, List<Object>, Queue<Object>, since primitives cannot be directly placed in these data structures they must be boxed in the wrapper classes. But, here's the good news, with the new Java 5.0, there is no need no worry about wrapper classes and boxing and unboxing (unless it's something taught in class), since there is auto-boxing and unboxing, therefore, one can directly "add" primitives to a data structure and let the JVM do the rest.


What is type wrappers in java?

A wrapper class in the Java programming language is one of eight classes provided in the java.lang package to create objects for the eight primitive types. All of the primitive wrapper classes in Java are immutable. Wrapper classes are used to represent primitive values when an Object is required. The wrapper classes are used extensively with Collection classes in the java.util package and with the classes in the java.lang.reflect reflection package. The Wrapper classes are: 1. Byte 2. Short 3. Integer 4. Long 5. Float 6. Double 7. Character 8. Boolean The Byte, Short, Integer, Long, Float and Double are all subclasses of the Number class. If you notice, the names of these wrapper classes are just the same as their primitive data type with a capitalized first letter. These wrapper classes start with a upper case alphabet while their primitive counterparts start with a lowercase alphabet.


What is wrapper class and its use?

When we need to store primitive datatypes(The data types we use in genera like:int,long,float etc)as objects, we use wrapper classes.Means in utility classes all the utility classes stores Objects.So when we need to store a primitive datatype,We make an object of that primitive data and store it. Say supposing there is a requirement to store only the object in an array A.The Primitive types cannot be stored in the same array as the array can accommodate only Objects here is where Wrapper Class come into picture.ie, we create wrapper for the primitive types.One such example is as below Ex:int i; Wrapper class for the primitive type(int) is created as below: Integer i = new Integer(); That's why we use Wrapper classes in Java


Is String class a final class?

The core classes in the java.lang.* package (e.g. String, Integer, double, Boolean, etc.) are all declared final.


Java program to illustrate Wrapper class?

java uses simple or primitive data types, such as int, char and Boolean etc. These data types are not part of the object hierarchy. They are passed by value to methods and cannot be directly passed by reference. However, at times there is a need to create an object representation of these simple data types. To address this need, Java provides classes that correspond to each of these simple types. These classes encapsulate, or wrap, the simple data type within a class. Thus, they are commonly referred to as wrapper classes. Wrapper classes corresponding to respective simple data types are as given in table below. Primitive Data Types Wrapper class byte Byte short Short int Integer long Long char Character float Float double Double boolean Boolean void Void eg Say supposing there is a requirement to store only the object in an array A.The Primitive types cannot be stored in the same array as the array can accommodate only Objects here is where Wrapper Class come into picture.ie, we create wrapper for the primitive types.One such example is as below Ex:int i; Wrapper class for the primitive type(int) is created as below: Integer i = new Integer();

Related questions

What are object wrappers?

Wrapper classes are classes that are used to make primitive variables into objects, and to make wrapped objects into primitives. int, boolean, double are all primitive data types and their respective wrapper classes are Integer, Boolean, and Double. Wrapper classes are useful in storing primitive data types in higher level data structures such as Stack<Object>, List<Object>, Queue<Object>, since primitives cannot be directly placed in these data structures they must be boxed in the wrapper classes. But, here's the good news, with the new Java 5.0, there is no need no worry about wrapper classes and boxing and unboxing (unless it's something taught in class), since there is auto-boxing and unboxing, therefore, one can directly "add" primitives to a data structure and let the JVM do the rest.


What is type wrappers in java?

A wrapper class in the Java programming language is one of eight classes provided in the java.lang package to create objects for the eight primitive types. All of the primitive wrapper classes in Java are immutable. Wrapper classes are used to represent primitive values when an Object is required. The wrapper classes are used extensively with Collection classes in the java.util package and with the classes in the java.lang.reflect reflection package. The Wrapper classes are: 1. Byte 2. Short 3. Integer 4. Long 5. Float 6. Double 7. Character 8. Boolean The Byte, Short, Integer, Long, Float and Double are all subclasses of the Number class. If you notice, the names of these wrapper classes are just the same as their primitive data type with a capitalized first letter. These wrapper classes start with a upper case alphabet while their primitive counterparts start with a lowercase alphabet.


What is wrapper class and its use?

When we need to store primitive datatypes(The data types we use in genera like:int,long,float etc)as objects, we use wrapper classes.Means in utility classes all the utility classes stores Objects.So when we need to store a primitive datatype,We make an object of that primitive data and store it. Say supposing there is a requirement to store only the object in an array A.The Primitive types cannot be stored in the same array as the array can accommodate only Objects here is where Wrapper Class come into picture.ie, we create wrapper for the primitive types.One such example is as below Ex:int i; Wrapper class for the primitive type(int) is created as below: Integer i = new Integer(); That's why we use Wrapper classes in Java


What is meant by wrapper classes?

Java has several "primitive" types (byte, short, int, float, double, boolean, char). Wrapper classes refer to the classes which "wrap up" each of these. For example, the Byte class contains a byte primitive and the methods to modify the class.


Is String class a final class?

The core classes in the java.lang.* package (e.g. String, Integer, double, Boolean, etc.) are all declared final.


Java program to illustrate Wrapper class?

java uses simple or primitive data types, such as int, char and Boolean etc. These data types are not part of the object hierarchy. They are passed by value to methods and cannot be directly passed by reference. However, at times there is a need to create an object representation of these simple data types. To address this need, Java provides classes that correspond to each of these simple types. These classes encapsulate, or wrap, the simple data type within a class. Thus, they are commonly referred to as wrapper classes. Wrapper classes corresponding to respective simple data types are as given in table below. Primitive Data Types Wrapper class byte Byte short Short int Integer long Long char Character float Float double Double boolean Boolean void Void eg Say supposing there is a requirement to store only the object in an array A.The Primitive types cannot be stored in the same array as the array can accommodate only Objects here is where Wrapper Class come into picture.ie, we create wrapper for the primitive types.One such example is as below Ex:int i; Wrapper class for the primitive type(int) is created as below: Integer i = new Integer();


What are the functions and variables of all the wrapper classes and their uses?

Wrapper classes wrap primitive types (eg: int, double, etc) in Objects which can be placed into Vectors, and many, many other uses. *Notice that an Object starts with a capital letter, while the primitives all start with a lowercase.Also notice that Strings are Ojects. These Wrapper classes can be created in many ways, so i will start slow, simply returning objects with a String. Ex: Integer from String: Integer i = Integer.valueOf("125");


What is a Wrapper Class in java?

Wrapper classes wrap primitive types (eg: int, double, etc) in Objects which can be placed into Vectors, and many, many other uses. *Notice that an Object starts with a capital letter, while the primitives all start with a lowercase. Also notice that Strings are Ojects. These Wrapper classes can be created in many ways, so i will start slow, simply returning objects with a String. Ex: Integer from String: Integer i = Integer.valueOf("125");


What are the only types in Java that are not classes?

The non-class Java data types are primitives: * byte * short * int * long * float * double * boolean * char


How many bytes required for int float double char boolean?

Int: 4 bytes Float: 4 double: 8 char: 1 boolean: 1


What is autoboxing in java?

With the advent of Java 2.0 (yay!!!), now when a method expects an Object as its parameter can be passed a primitive data type (i.e. int, double, char) and automatically "box" it into its corresponding Wrapper Object (i.e. Integer, Double, Character), thus primitives could be passed as an Object parameter. It also works the other way, "auto-unboxing" you can directly modify primitives Wrapper Objects with primitive operations(i.e. +, -, /, %) For example: Integer myInt = new Integer( 10 ); // creates an Integer holding 100 int yourInt = myInt * 10; // yourInt is now a primative holding 100 myInt = myInt * 10; // myInt also holds 100


What are Class Constructor and Primitive data types?

class constructor is a function which has the same name as the class name and has no return type. primitive data types are the fundamental data types which are independent. eg:int,char,float etc..............