Wrapper Classes

Wrapper Classes

Need For Wrapper Class

  1. The need for wrapper classes is to wrap primitives into objects so that we can handle primitives like objects.

  2. To define several utility functions which are required for primitives.

Primitive Data Types

  1. int

  2. short

  3. float

  4. long

  5. byte

  6. boolean

  • For each primitive data type, we have an equivalent wrapper class as shown below

    1. byte-Byte

    2. int-Integer

    3. char-Character

    4. float -Float

    5. short-Short

    6. bool - Boolean

  • Almost every wrapper class contains two constructor

    1. One takes a primitive type as input

    2. The second one takes string type as input

  • If the string input I not properly formatted, that is if the input is not a number then we will get NumberFormat Exception

  • Character class contains only one constructor which can take only input type character only