Ads Sponsored By Google :)

Sunday, 13 January 2013

use of|Definition integer wrapper class in java with example


wrapper class in java with example wrapper class in java example use of wrapper class in java integer wrapper class in java wrapper class in java


Wrapper Class:
         Java is an object-oriented programming language and  everything in java would exists as an object.  primitive data types in java. Java has feature called Collection Frame Work such all data types elements are stored as an object in Collection.Java allows you to include the primitives in the family of objects to convert all objects into their respective fundamental data type by using Wrapper class

   Definition Of Wrapper Class:
     Each and every data type in java their exists a predefined class in java api is known as wrapper class.
    The purpose of wrapper class is that to convert string data into fundamental data.
    In general each and every wrapper class contains the following generalized methods which will convert  String data into fundamental data.

Syntax:
   Public static Xxx parseXxx(String);
Here Xxx represents any data type except  character data type.

The following are the data types and wrapper classes
Fundamental        Wrapper Class Name                  Conversion method                                                                                                                                                                                                    Data type                                                    (from String to fundamental data type)
   
    byte                             Byte                     public static byte ParseByte(String)
    short                            Short                   public static short ParseShort(String)
    int                                 Integer                public static int ParseInt(String)
    long                              Long                   public static long ParseLong(String)
    float                              Float                   public static  float ParseFloat(String)
   double                          Double                public static double ParseDouble(String)
   boolean                        Boolean              public static boolean ParseBoolean(String)

The Following program illustrate the concept of wrapper classes
     Class demo
   {
     int n;
     void set(int x)
   {
     n=x;
   }
      void table()
    {
       for(int  i=1;i<=10;i++)
    {
      System.out.println(n+”*”+i+”=”+(n*i));
     }
  }

  Class maindemo
{
   Public static void main(String args[])
  {
     if(k.length!=1)
   {
     System.out.println(“plz enter only one value”);
   }
  else
   {
     int x=Integer.parseInt(args[0]);
     if(x<=0)
    {
     System.out.println(x+”is invalid input”);
    }
  else
   {
       demo  d=new demo();
       d.set(x);
       d.table();
     }
   }
  }

Wrapper Class Conversions or Data Conversions:

        Conversion data of one type to another type as follows..

                   Click Here  to view more details for the Data Conversions

No comments:

Post a Comment

LinkWithin