Wrapper Classes

Wrapper Class: The primitive data type in java is not object. Some of built-in-classes handle only objects so to convert primitive to object we use wrapper class.

object to primitive :  // called un-boxing
  byte b = obj.byteValue();

primitive to object : // refer as a boxing
byte b;
Byte obj = new Byte(b);

Numeric objects to String objects
String str = obj.toString();


String object to Numeric objects
Byte obj = Byte.valueOf(str);

String object to primitive number
byte b = Byte.parseByte(str);

System.out.println(Byte.MAX_VALUE);
System.out.println(Byte.MIN_VALUE);
System.out.println(Byte.SIZE);


Character class:
Constructor: Character chObj  = new Character('c');

Boolean Class:
Boolean obj = new Boolean();

Auto-Boxing : primitive type is automatically converted to object without any casting.
Integer obj = 200; //auto-boxing;

int i = obj   //auto-unboxing





Comments

Popular posts from this blog

Introduction to Java

Creational Design Pattern: Factory Design Pattern

Design Patterns: The Secret Weapon of Expert Developers