Professional Documents
Culture Documents
PPL Unit 6
PPL Unit 6
UNIT-VI
Seminar Interim
Presentation
Exception – Handling
Project Department
in JAVA
of Technology
Presentation-DOT
*
R
E
S
E
A
R
Belhe C
E
E-mail: REjadhavganesh874@gmail.com
V
I
I
T
*
*
*
Seminar PresentationInheritance
– Department
* of Technology
R
E
S
Exception Handling E
A
R
C
•Exception Definition H
• Exception OccurrenceC
E
N
•Exception Handling T
R
•Exception Propagation E
V
I
I
T
*
*
*
Exception
Seminar Presentation – Department
* of Technology
R
E
•Error occurred in execution
S time
•Abnormal termination ofEprogram
A
•Wrong execution result R
•Provide an exception handling
C mechanism in language system
• Improve the reliability
H
of application program
• Allow simple program
C
code for exeception check and
handling into source
E
N
T
R
E
V
I
I
T
*
*
*
Exception Types
Seminar Presentation – Department
* of Technology
R
E
S
Checked Exception E
A
Object S
E
A
Throwable
R
C
H
Error Exception
C
E
N
T
RuntimeException
R
… E …
V
I
…
I
T
*
*
*
Exception
Seminar Presentation Class of Technology
– Department
*
R
E
S
E
ClassNotFoundException RuntimeTimeException IOException
A
R
C
H
EOFException E
ArithmeticException
N
FileNotFoundException
T ClassCAstException
UnknownHostException
R IllegalArgumentExceptio
MailFormedURLException
E
n
V IndexoutBoundException
I NullPointerException
I
T
*
*
*
Seminar PresentationException
– Department
* of Technology
R
E
•Using try-catch, throw, throws,
S finally mechanism
•Try block may be followed E with one or more catch/finally
block A
R
•If no error occurs in try block
C catch block is bypassed.
•If error occurs in try block
H , java creates an object of a
particular type and throw it.
C
• It check for matching E catch block exists.
N
T
R
E
V
I
I
T
*
*
*
Seminar PresentationExample
– Department
* of Technology
R
E
try
S
{
E
// sample code
A
}
R
catch(object)
C
{
H
// message
}
C
E
N
T
R
E
V
I
I
T
*
*
*
Example
Seminar Presentation – Department
* of Technology
R
E
Class exception_test S
{ E
try H
{
C
int x=20, y=0, Z; E
System.out.println(“Before
N error”);
z = x/y; T
R
System.out.println.(“After
E
error”);
}
catch(ArithmeticException
V
ae)
I
{ System.out.println(“Don’t
I
divide by Zero”);
} T
System.out.println(“After
* try catch block”);
*
}}
*
Java’s Built-in
Seminar Presentation Exceptions
– Department
* of Technology
R
E
Exception Meaning
S
ArithmeticException Arithmetic
E error such as divide by
A
R
zero
ArrayStoreException Storing
C wrong data type in array
ArrayIndexOutOfBoundsException
H Array index is out
of Bound
C
E
FileNotFoundException N Attempt to access non existed file
IOException T
General input/output error
R
SecurityException E
Attempt to violate security
NumberFormatException Invalid conversion
V
I
I
T
*
*
*
Use of
Seminar Presentation Exception
– Department
* of Technology
R
E
{ C
// sample code H
} C
catch (Exception e) E
{ N
T
// message R
} E
V
I
I
T
*
*
*
Exception Occurrence
Seminar Presentation – Department
* of Technology
R
E
•Raised implicitly by system
S
•Raised explicitly by programmer
E
•Throw Statement A
R
C Throwable
H class or its
C
sub class
E
N
throw ThrowableObject;
T
R
E
V
I
I
T
*
*
*
} H
int i = 0; T
R
ThrowStatement.exp(i);
E
}
} V
I
java.lang.NullPointerException
I
T
at ThrowStatement.exp(ThrowStatement.java:4)
*
at ThrowStatement.main(ThrowStatement.java:8
*
*
Seminar Presentationfinally
– Department
* of Technology
R
E
•It executes whether or not San exception is thrown.
•Finally block is optional E
•Each try block must have either
A
one catch or finally block.
R
•Generally used to free resources.
C
H
C
E
N
T
R
E
V
I
I
T
*
*
*
Example
Seminar Presentation * - Finally
– Department of Technology
R
E
Public class finallyDemo S
{ E
try{ H
System.out.println(“Inside A”);
C
throw new IOException(“Sample
E throw”);
} N
finally T
R
{ E
System.out.println(“Finally of A”);
} V
I
} I
} T
*
*
*
JAVA
Seminar Presentation * I/O
– Department of Technology
R
E
•Import java.io.*; S
•I/O E
A
R
Console based Abstract
C window toolkit (AWT)
H
V
I
I
T
*
*
*
InputStream OutputStream
N
Reader Writer
T
V
I
I
T
*
*
*
Reading
Seminar Console Input
Presentation * using BufferedReader
– Department of Technology
R
E
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
S
char c;
E
c = (char) br.read(); // character reading
A
System.out.println( c );
R
String str;
C
str= br.readLine(); // string reading
H
int n;
n = Integer.parseInt(str); // integer reading
C
E
N
T
R
E
V
I
I
T
*
*
*
Writing Console output
Seminar Presentation – Department
* of Technology
R
E
S
E
A
System.out.write(val); R
C
H
System.out.write(“\n”); C
E
N
T
R
E
V
I
I
T
*
*
*
Print –writer
Seminar Presentation class of Technology
Department
*
R
E
S
Used to write contents onE the console Printwriter class is
character base A
R
C
Constructor H
PrintWriter(OutputStream output, boolean flushnewline)
C
E
Class supports for print and
N
println method
T
pw.println(val); E
} V
} I
I
T
*
*
*
Seminar Applets
Presentation – Department
* of Technology
R
E
V
I
I
T
*
*
*
Life cycle
Seminar Presentation * of Applet of Technology
– Department
R
•Init() – initialization E
S
• It loads applet in memory.
E
V
I
I
T
*
*
*
Applet
Seminar Presentation *Skeleton
– Department of Technology
R
E
//java file
S
import java.applet.*;
E
public class appskl extends Applet A
{// called first R
public void init() C
{// initialization;} H
// called second , after init()
public void start(){// start execution}
C //
called when applet stopped E
public void stop(){….} N
//java file A
R
import java.applet.*; C
public class welcome extends
H Applet
{
C
public void paint(Graphics
E
g)
{ N
} V
I
// HTML file I
<applet code=welcome width=300
T height=150>
</applet> *
*
*
C
E
N
T
R
E
V
I
I
T
*
*
*
How to Execute
Seminar Presentation Applet?
– Department
* of Technology
R
E
S
•1) in WebBrowser E
A
C
E
N
T
R
E
V
I
I
T
*
*
*
Applet
Seminar Presentation *program
– Department of Technology
R
E
S
import java.applet.*; E
public class app_color extends
A Applet
{ R
C
String msg; H
public void init()
{ setBackground(Color.red);
C
E
msg = “Inside init()”;N
} T
msg = “InsideVpaint()”;
g.drawString(msg,
I 10,30);
} I
T
} *
*
*
Seminar PresentationExample
– Department
* of Technology
R
E
S
package mypack; E
public class Balance A
{ R
C
String name; H
double bal;
public Balance(StringC n, double b)
E
{ N
name = n; T
bal = b; R
} E
S.o.p.(name +“ ”+bal);
I
T
} *
} *
*
Importing
Seminar package in sample
Presentation – Department
* of Technology
R
E
S
import mypack.*; E
public class sample A
{ R
C
public static void main(String
H
args[])
{
Balance b = new Balance(“sham",20000);
C
E
b.show(); N
} T
} R
E
C
E
N
T
R
E
V
I
I
T
*
*
*
Requesting Repaintaing
Seminar Presentation – Department
* of Technology
R
E
•Applet writes to window Swhen paint method is called
•When applet want to update
E
infromation that has to
A
displayed in window, it calls
R repaint.
C
Repaint()-> update()->paint()
H
C
Repaint method call ways:E
1. void repaint( ) // EntireN window repainted
T
2. void repaint(int left, intRtop, int width, int height) //
specified pixel repainted. E
3. void repaint(long maxDelay) //repaint after specified
V
delay I
4. void repaint((long time,I int left, int top, int width, int
height) //specified pixel repainted
T with speciifed pixel
*
delay *
*
Status Window
Seminar Presentation – Department
* of Technology
R
String msg;
C
public void init() E
{ setBackground(Color.red);
N
} R
E
public void paint(Graphics g)
{ V