0% found this document useful (0 votes)
2 views124 pages

Java Lang Package

The document provides an overview of the Object class in Java, detailing its key methods such as toString(), hashCode(), and equals(), which are essential for object manipulation and comparison. It also discusses the differences between String, StringBuilder, and StringBuffer, highlighting their mutability and immutability. Additionally, it covers wrapper classes, utility methods, and concepts like autoboxing and autounboxing introduced in Java 1.5.

Uploaded by

Anita Maan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views124 pages

Java Lang Package

The document provides an overview of the Object class in Java, detailing its key methods such as toString(), hashCode(), and equals(), which are essential for object manipulation and comparison. It also discusses the differences between String, StringBuilder, and StringBuffer, highlighting their mutability and immutability. Additionally, it covers wrapper classes, utility methods, and concepts like autoboxing and autounboxing introduced in Java 1.5.

Uploaded by

Anita Maan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 124

Java.lang.

packag
e
What is objects class?
 For any java object whether it is
predefine or customized the most
commonly required methods are
encapsulated into a separate class which
is nothing but object class.
Method present in objects class?
Public string toString()
 1. We can use this method to get string representation
of an object.
 2. Whenever we are try to print any object reference

internally toString() method will be executed


 1. We can use this method to get string representation
of an object.
 2. Whenever we are try to print any object reference

internally toString() method will be executed


Public native int
hashCode()
 1. For every object jvm will generate a unique number
which is nothing but hashCode.

 2. Jvm will using hashCode while saving objects into


hashing related data structures like HashSet, HashMap,
and Hashtable etc.

 3. If the objects are stored according to hashCode


searching will become very efficient (The most powerful
search algorithm is hashing which will work based on
hashCode).
equals() method:
 1. We can use this method to check equivalence of two
objects.

 2. If our class doesn't contain .equals() method then


object class .equals() method will be executed which is
always meant for reference comparison[address
comparison].

 i.e., if two references pointing to the same object then


only .equals( ) method returns true .
Differences between == (double equal
operator) and .equals() method?
Clone () method:
Shallow cloning
Deep cloning
getClass() method :
Finalize()
wait( ) , notify( ) ,
notifyAll( )
 We can use these methods for inter thread
communication
Why String is immutabiity?
SCP And Heap ?
What is the main difference
between String and StringBuilder?
What is the main difference
between String and StringBuffer ?
Other than immutability and mutability is
there any other difference between String and
StringBuffer ?
What is the meaning of
immutability and mutability?
Explain immutability and
mutability with an example?
What is SCP?
What is the advantage of
SCP?
What is the disadvantage of
SCP?
Why String objects are immutable where
as StringBuffer objects are mutable
What is the difference between
final and immutability?
Final vs immutability :
 final modifier applicable for variables where
as immutability concept applicable for
objects
StringBuffer sb=new StringBuffer();
what is default size ?
StringBuilder which version
come ?
What is Method chaining?
Wrapper classes ?
 1. To wrap primitives into object form so
that we can handle primitives also just like
objects.

 2. To define several utility functions which


are required for the primitives.
Utility methods:
 1. valueOf() method.
 2. XXXValue() method.
 3. parseXxx() method.
 4. toString() method.
valueOf() method :
valueOf() method :
 We can use valueOf() method to create

wrapper object for the given primitive or


String this method is alternative to
constructor.
xxxValue() method :
 We can use xxxValue() methods to convert
wrapper object to primitive
charValue() method:
 Character class contains charValue()
method to convert Character object to char
primitive
booleanValue() method:
parseXxx() method :
 We can use this method to convert String to
corresponding primitive.
 class WrapperClassDemo
 {
 public static void main(String[] args)
 {
 int i=Integer.parseInt("10");
 boolean b=Boolean.parseBoolean("ashok"); double
d=Double.parseDouble("10.5");
System.out.println(i);//10
 System.out.println(b);//false
System.out.println(d);//10.5
 }
 }
toString() method
 We can use toString() method to convert
wrapper object (or) primitive to String.
 class WrapperClassDemo

 {
 public static void main(String[] args)
 {
 Integer i=Integer.valueOf("10");

System.out.println(i);//10
System.out.println(i.toString());//10
 } }
Autoboxing and Autounboxing
(1.5v)
 Until 1.4 version we can't provide wrapper
object in the place of primitive and primitive
in the place of wrapper object all the
required conversions should be performed
explicitly by the programmer.
 class AutoBoxingAndUnboxingDemo
 {
 public static void main(String[] args)
 {
 Boolean b=new Boolean(true);
 if(b)
 {
 System.out.println("hello");
 }
 }
 }
 Output: hello
 Output: hello
Autoboxing :
Autounboxing :

You might also like