Advanced Topic in Java
Advanced Topic in Java
Advanced Topic in Java
lang package
• java.lang is a imported by default in all the
classes that we create.
• Remember String and System class
Java.lang.Object class
Output
My Demo Object created
Java Wrapper classes
• For each primitive type, there is a corresponding
wrapper class designed.
• Are wrapper around primitive data types.
• allow for situations where primitives cannot be used
but their corresponding objects are required.
• Normally Used to convert a numeric value to a String
or vice-versa.
• Just like String, Wrapper objects are also
immutable
Wrappers classes
Wrapper classes (contd.)
• converts primitive to wrapper
– double a = 4.3;
– Double wrp = new Double(a);
• Each wrapper provides a method to return the
primitive value.
– double r = wrp.doubleValue();
Converting Primitive types to wrapper
objects
• Integer ValueOfInt = new Integer(v)
• Float ValueOfFloat = new Float(x)
• Double ValOfDouble = new Double(y)
• Long ValueOfLong = new Long(z)
Converting wrapper objects to primitives
• int v = ValueOfInt.intValue();
• float x = ValueOfFloat.floatValue();
• long y = ValueOfLong.longValue();
• double z = ValueOfDouble.doubleValue();
Converting primitives to String Object