What are Wrapper Classes and why we use in java
Posted By Vakeel Malik | 31-Oct-2018
When the user does register in any web application then enter some information like email id and mobile number etc, send all these data to the server in form of objects. email id is sent in form of the string and mobile in form of the int. string is a class easily sent to the server but can not send an int to the server in form of an object. because an int is a primitive data type. we need to convert primitive data type to object. the wrapper classes are used to convert primitive data type to object. wrapper classes are also used in collection framework. when a programmer works on java.util.*; the package needs wrapper classes. because java.util.* the package works on the only object, not on the primitive data type.
When we convert primitive data types to objects and wise verse needs some class. this class is called the Wrapper class. the wrapper class also use in the collection. each data type has a corresponding wrapper class
there are some predefined wrapper classes.
Data type Wrapper classes
1. byte Byte
2. short Short
3. int Integer
4. long Long
5. float Float
6. double Double
all wrapper classes are the subclass of Number class. Number class is a superclass of all wrappers class which contains some abstract methods and some non-abstract methods.
there are some methods of number class
these all methods are static methods which will call with the class name these methods are used to convert Object to respective primitive data type. all methods will be available in wrapper classes because wrapper class derived from number class.
how to use these methods:-
Program to accept an integer number from keyword and convert it into