0% found this document useful (0 votes)
3 views3 pages

Java StringBuffer and Exception Handling

The document provides an overview of StringBuffer and StringBuilder classes in Java, highlighting their mutability, constructors, and differences in thread safety. It also discusses wrapper classes for primitive data types and introduces exception handling, including types of exceptions such as checked and unchecked exceptions. Examples of usage for StringBuffer and StringBuilder are included to illustrate their functionality.

Uploaded by

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

Java StringBuffer and Exception Handling

The document provides an overview of StringBuffer and StringBuilder classes in Java, highlighting their mutability, constructors, and differences in thread safety. It also discusses wrapper classes for primitive data types and introduces exception handling, including types of exceptions such as checked and unchecked exceptions. Examples of usage for StringBuffer and StringBuilder are included to illustrate their functionality.

Uploaded by

marymanasa7902
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

StringBuffer:----

----------------------
1)StringBuffer is a class present in the [Link] package

2)StringBuffer is also a final class, so it can not be inherit

3)SB is a mutable class so it is possible to change the content in the same


location

Constructors:----
----------------------------
1)StringBuffer sb=new StringBuffer();

2)StringBuffer sb1=new StringBuffer(int capacity);

3)StringBuffer sb2=new StringBUffer(String str);

class SBTest
{
public static void main(String args[])
{
StringBuffer sb=new StringBuffer();
[Link]([Link]());//default capacity is a 16

StringBuffer sb1=new StringBuffer(5);


[Link]([Link]());

StringBuffer sb2=new StringBuffer("digitinstitute");


[Link]([Link]());
}
}
-----------------------------------------------------------------------------
StringBuffer is a mutable:----
-----------------------------------
Once we are creating the STring object it is possible to the modification on
existing object it is called as a
mutability nature

class SBMutable
{
public static void main(String args[])
{
StringBuffer sb=new StringBuffer("Hyderabad");
[Link]("How are you?");
[Link](sb);
}
}
---------------------------------------------------------
StringBuilder:----
-------------------------
It is inroduce in jdk1.5 version

StringBuilder exactly same as StringBuffer except one imp difference

Every method present in the StringBuilder is not Synchronized means threads are not
required to wait so not thread safe

multiple threads are allow to operate on StringBuilder methods hence performance of


the application is increased.
Wrapper Classes:----
-----------------------
To repraents primitive data types as a Object form we required some classes those
classes are called as a Wrapper classes

[Link] package

byte-------->Byte

short------->Short

int--------->Integer

long-------->Long

float------->Float

double------>Double

boolean------>Boolean

char--------->Character
------------------------------------------------------
class SBTest
{
public static void main(String args[])
{
StringBuffer sb=new StringBuffer();
[Link]([Link]());//default capacity is a 16

StringBuffer sb1=new StringBuffer(5);


[Link]([Link]());

StringBuffer sb2=new StringBuffer("gammainnovations");


[Link]([Link]());
}
}

-------------------------------------
class SBMutable
{
public static void main(String args[])
{
StringBuilder sb=new StringBuilder("Hyderabad");
[Link]("How are you?");
[Link](sb);
}
}
---------------------------------------------------------------
Exception Handling:----
----------------------------
90 years--------->4am

1cr----->ATM

--->card insert---->wrong---->NullPointerException

Bank-------->software company----->Sun microsystem---->technical error------


>userfriendly information(endusers)

NullpointerException------>Hello boss your entered pin is wrong, plese enter


correct pin

Exception:-----
--------------------
--->An exeception is an a problem occured during execution time of the program

--->An exeception is a unwanted unexpected event that event distrubs the normal
flow of the execution called as a

exception.

Types of Exceptions:----
-------------------------------
As per sun micro systems standards the exceptions are divided into 3 types

1)Checked Exceptions

2)Unchecked Exceptions

3)Error
----------------------------------------
1)Checked Exceptions:----
----------------------------
The exceptions which are checked by the compiler at compilation time

1)ClassNotFoundException:----If the loadded class is not avialable

2)IllegalAccessException:---Access to a class is denied

3)InstantiationException:---Attempt to create an object of a abstract class and


interface

4)NoSuchFieldException:---A requested field does not exist

5)NoSuchMethodExcetion:---If the requested method does not exist

2)Unchecked Exception:-----
---------------------------------

You might also like