Exceptions - Sub set of errors. Errors - any abnormal conditions. Type of errors compile time errors.

* we can't trapped(Ignore). ; , a , system, integer Runtime errors. * we can trap by using the Exception handling. / by 0 , NumberFormat , array index

all run time errors r called Exceptions & base class of all exception - java.lang.Throwable java.lang - package , this is default import. Throwable - class - it has 2 sub classes. java.lang.Error * we can't handle. * end with Error NoSuchMethodError java.lang.Exception * we can handle. * end with Exception ArithmeticException

Adv / need of Exception handling - by using the exception handling, we can control the abnormal termination of program. java.lang.Error - it has 1- NoSuchMethodError - if method not found, like program without using p s v m 2- NoClassDefFoundError - if class def not found. java Haha 3- StackOverFlowError - if JVM stack is full - (memory problem ) class Stack { public static void main(String aa[]) { System.out.println("Vivek says, I m a good boy"); main(aa); // recursive main calling. } } in this program we have StackOverFlowError ___________________________________________________________________ java.lang.Exception - it has Exceptions Type CheckedException UnCheckedException * need to handle, else we have compile * no need to handle, but if any time error(must be in try catch or exception in Runtime then with throws) program terminate. UnCheckedException -

valid int a[] = new int[-5]. pass 5 20 10 haha value of a a = 5 a = 20 a = 10 a = NumberFormatException 3.ArithmeticException . String s = "Harsh".StringIndexOutOfBoundsException ./ by 0 int a = Integer.RuntimeException 1. pass 5 20 10 0 value of x x = 20 x = 5 x = 10 x = ArithmeticException 2. pass 5 20 10 no argument value of a a = 5 a = 20 a = 10 a = ArrayIndexOutOfBoundsException int a[] = new int[5].ArrayIndexOutOfBoundsException ii .if array & String index not exist. .parseInt(aa[0]).IndexOutOfBoundsException .NullPointerException .array index 0 to 4 a[26] = 10. int a = Integer.NegativeArraySizeException 2.parseInt(aa[0]).ArrayIndexOutOfBoundsException .if String index not exist. char c = s. // get user id parameter from request obj ect if parameter not passed by the user then u is null & u use in future then we have NullPointerException .charAt(2). c = 'r'. .if object is null. c = StringIndexOutOfBoundsException 4.char at 2 index. int x = 100 / a. . . .NumberFormatException .invalid number for type casting int a = Integer. Major is project Development. start 0 to n char c = s. i .if array index not exist.charAt(26). String u = req.getParameter("t1").if array size -ve int a[] = new int[5].NegativeArraySizeException .parseInt(aa[0]).-----------------1.

add in jdk1. // Arithmetic System. finally . class Ex1 { public static void main(String aa[]) { int a = Integer.in JDBC programming . Class. if yes then handle in catch block. constraints prob.in Runtime input & file handling.parseInt(aa[0]).in RMI programming.SQLException .IOException .SerevletException .in EJB programming.32999.'20-Jan-1989')") . s.use with condition for genarate the new exception throws .out.println("x = "+x).'Vivek Sharma'. .driver.in JDBC programming. 5.FileNotFoundException . 9.check the code there is any Exception or not. if any type of Remote problem. 10.UnkownHostException .RemoteException . . if RemoteServer object not found.if file not found for input. if Remote PC not found. 11.CheckedException ---------------3. ____________________________________________________________________ how to handle try .NotBoundsException .SecurityException .InterruptedException . package my.ClassNotFoundException .like table not exist.if runtime input mismatch.for connectivity with oracle. catch . col type mismatch .InputMismatchException .use with method body for handling the exception ** one try block should have one catch or one finally block .find out the exception type.for any type of SQL related problem .if file currepted 14. 7.in multi Threaded programming .in Socket programming.in Applet programming. 6. // NumberFormat + ArrayIndex int x = 100 / a.OracleDriver"). 8.execute("insert into emp values(1001.in Servlets programming 12.must.in RMI programming. 15.StreamCurreptedException . number of cols less.5 for Scanner class. but if oracle not installed in PC then we have ClassNotFoundException 4. this is optional throw .CreateException .at the end of try & catch block. 13.jdbc. database read only.forName("oracle.

in.println("Welcome "+new String(b)).byte by byte. . } } // javac -d . * Type casting not supported. if int ans in int java Sum 100.println("Welcome "+s).has max limit.add if String .Sum is = 150.Sum is = 150. 2.Ex1 5 // Thanx msg display only when there is no exception pass any number of command line argument. 10 inputs . if they r numbers .to create an byte array byte b[] = new byte[10].Sum is = 150 --------------------------------------------------------------------Runtime inputs in java System.out.read(byte[]) DataInputStream / BufferdReader * static input .out.No Max Limit. 3 & 4 th step System. Ex1.println("Thanxxxxxxxxxxxxxxxxxxxxxxxxxx").parseInt() input with read() method 1.System.1 input . 4.out. * Dynamic Input . finally no use.has max limit.in.22 50.pass in read method System.read(b) 3. problem with read() method * * * * static input .22 50 java Sum 100 50 ans . * Line Mode .66 ans . * byte mode .concat pass 2 command line argument if they r float values then ans in float .display System.22 ans . More Complex .44 java Sum 100. 4 lines .java // java my.read whole Line. Type casting not supported.10 *4 = 40 Lines.convert into String String s = new String(b). * type casting Supported .

part of java1 * support 256 charset only (English only) * work with warnings. long. . double.read single word only.in)).read whole line * Adv . String s = r.Line Mode .---------------------------------------------------------------------input with DataInputStream DataInputStream r = new DataInputStream(System.work without warnings.read/input float value long nextLong() . * More complex * finally . String s = r.readLine(). * end with Stream char mode * new concept . * end with Reader/Writer -------------------------------------------------------------------input with BufferedReader char mode byte to char byte mode BufferedReader r = new BufferedReader(new InputStreamReader(System.read/input long value double nextDouble() .5 for Runtime input . .add of java2 * support 512 charset also (National charset . int nextInt() . .work with warnings.in). byte for that we need to type casting.unicodes) * work without warnings. like int.with Scanner class Scanner r = new Scanner(System. String nextLine() . -----------------------------------------------------------------I/O Operations Byte Mode * old concept .no use ___________________________________________________________________ new concept add in jdk1.in).read whole line.read/input byte value String next() .read/input double value byte nextByte() .read whole line Adv . * no method for primitive data input.readLine(). float. problems * no method for input single word/char only.Dynamic Input * problem .read/input int value float nextFloat() .

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.