Friday, 14 June 2013

STRING BUFFER

in this discussion we will discuss about buffer string buffer
 [12:30-3:30]--PROGRAM USING STRING BUFFER.....which includes
----)buff.delete(2,3 );////////////////////to delete char from 2-3
-----)buff.deleteCharAt(i );///////////delete the char at position i
-----)buff.capacity( );////////////////////length+16
-----)buff.append();//////////////////////append
-----)buff.reverse();/////////////////////to reverse a string
-----)buff.setLength();
-----)buff.insert(0," xknakgs");/////////////////////to insert  any string at position 0

import java.io.*;
import java.lang.*;
class Using_buffer

{
public static void main(String arg[])
{
StringBuffer buff=new StringBuffer("manu");
System.out.println("buffer = "+buff);//////////////////////////manu
buff.delete(1,2);
System.out.println("buffer after delete func = "+buff);////////mnu
buff.append(" manpreet ").append(" kaur ").append(" arora ");
System.out.println("buffer = "+buff.toString());/////////////////////////////mnu manpreet kaur arora
buff.setLength(20);
System.out.println("buffer = "+buff);///////////mnu manpreet kaur ar
buff.setLength(15);
System.out.println("buffer = "+buff);///////////mnu manpreet kau
buff.delete(0,3);
System.out.println("buffer="+buff);///////////manpreet kau
buff.insert(0,"hello");
System.out.println("buffer = "+buff);////////hello manpreet kau
System.out.println("buffer capacity="buff.capacity());///////36

}}


import java.lang.*;
public class Stringbuffer1
{
public static void main (String arg[])
{
StringBuffer buff=new StringBuffer("jasleen kaur");
System.out.println("buffer="+buff);
buff.delete(4,9);
System.out.println("after deletion"+buff);
System.out.println("after deletion"+buff.deleteCharAt(4));
System.out.println("capacity is"+buff.capacity());
buff.setLength(5);
System.out.println("buffer is"+buff);
buff.append("hello").append("java");
System .out.println(buff.toString());
StringBuffer buff1=new StringBuffer();
buff1.insert(0,2012);
buff1.insert(0,"java");
buff1.insert(0,"hello");
System.out.println("buffer is"+buff1);
System.out.println("reverse is"+buff1.reverse());

}
}


[3:30-6:30]-Than we had studied about EXCEPTION HANDLING

ERROR-Its is a condition in the program which may produce wrong result or interrupt the program.
three types of error..
1)compile time error-which include syntax error.
2)logical error-(eg. using greater than sign instead of less sign)
3)runtime error-(eg.divide by 0)
EXCEPTION HANDLING-In prog.lang some time our prog. compile or execute successfully but it compile
successfully and fail to execute the prog. such type of error interrupt the program and run time environment of the lang. automatically trow appropriate exception.

TYPES OF EXCEPTION CLASSES
1)builtin-which are already define  within the lang.
5 RESERVE KEYWORD
-try
-catch
-throw
-throws
-finally
some of the inbuilt exceptions are..........
-Arithmetic Exception
-ArrayIndexOutOfBoundException
-ArrayStoreException
-ClassCastException
-IllegalArguementException etc....
2)user defined exception-it can be created by user itself..
some of the user defined exceptions are
-Throwable FillInStackTrace()
-)Throwable GetCause()
-String GetLocalizeMessage()
-String GetMessage()
-Void PrintStackTrace()



No comments:

Post a Comment