Professional Documents
Culture Documents
Wrapper Classes 1
Wrapper Classes 1
Wrapper classes
• A wrapper class is a class whose object
wraps or contains a primitive data type
value.
• It is abstract class.
Number class methods
• byte byteValue();
• short shortValue();
• abstract int intValue();
• abstract long longValue();
• abstract float floatValue();
• double doubleValue();
Character class
which wrapsor contain a char value in
an object.
Constructor:
Character(char value)
Constructs a newly allocated Character
object that represents the specified char value.
Note: it has only one constructor (does not contain
with String argument).
Contd..
Methods:
• Char charValue();
Character c=new Character(‘A’);
char ch=c.charValue();// ch contains ‘A’
• public int compareTo(Character obj2);
int x=obj1.compareTo(obj2);
Returns 0 if both are equal.
negative obj1<obj2
positive obj1>ob2.
Contd…
String toString();
static boolean isWhitespace(char ch);
static boolean isWhitespace(int code);
static boolean isWhitespace(char ch);
static boolean isUpperCase(int unicode) ;
static boolean isUpperCase(char ch) ;
static boolean isLowerCase(int codePoint);
static boolean isLowerCase(char ch) ;
static boolean isUpperCase(char ch) ;
static boolean isUpperCase(int codePoint);
static boolean isLetterOrDigit(char ch) ;
static boolean isLetterOrDigit(int codePoint) ;
static String toString(char c) ;
static char toUpperCase(char ch) ;
static char toLowerCase(char ch) ;
Byte class
• Which wraps or contain byte value in the
object.
Constructors:
• Byte( byte num); // Byte b=new Byte(123);
• Byte(String obj);// Byte b1=new Byte(“12”);
Contd….
String toString();
int compareTo(Byte anotherByte);
static byte parseByte(String s) ;
static byte parseByte(String s, int radix) ;
static Byte valueOf(String s) ;
static Byte valueOf(byte b) ;
short shortValue() ;
byte byteValue();
boolean equals(Byte obj);
Short
• Which wraps a value of primitive data type short
in its object.
Constructors:
• Short( short num); // Short b=new Short(14007);
• Short(String obj);// Short b1=new Short(“14007”);
Contd….
String toString();
int compareTo(Short anotherByte);
static short parseShort(String s) ;
static short parseShort (String s, int radix) ;
static Short valueOf(String s) ;
static Short valueOf(short b) ;
short shortValue() ;
byte byteValue();
boolean equals(Short obj);
Integer
• Which wraps a value of primitive data type int in
its object.
Constructors:
• Integer( int num); // Integer b=new
Integer(14007);
• Integer(String obj);// Integer b1=new
Integer(“14007”);
Contd…
String toString();
int compareTo(Short anotherByte);
static int parseInt(String s) ;
static int parseInt (String s, int radix) ;
static Integer valueOf(String s) ;
static Integer valueOf(byte b) ;
short shortValue() ;
byte byteValue();
int intValue();
boolean equals(Short obj);
static String toHexString(int i);
static String toOctString(int i);
static String toBinaryString(int i);
Long
Constructors:
• Long( long num); // Long b=new Long(14007000);
• Long(String obj);// Long b1=new Long(“14007000”);
Contd…
String toString();
int compareTo(Short anotherByte);
static long parseLong(String s) ;
static long parseLong (String s, int radix) ;
static Long valueOf(String s) ;
static Long valueOf(long b) ;
short shortValue() ;
byte byteValue();
int intValue();
boolean equals(Short obj);
static String toHexString(long i);
static String toOctString(long i);
static String toBinaryString(long i);
Command line arguments
Command line arguments
• We can pass the arguments to main
method during the execution of the
program. These are called command line
arguments.