# What is User Defined Exception ?
Java supports exception handling by its try catch constructs. Exceptions are conditions which JVM or applications developed in java are unable to handle. These classes are derived from java.lang.Throwable class. User Defined Exceptions are those exceptions which an application provider or an API provider defines by subclassing java.lang.Throwable class. The statements following the throw keyword in a program are not executed.
# What is the difference between ‘throw’ and ‘throws’ ?And it’s application?
Exceptions that are thrown by java runtime systems can be handled by Try and catch blocks. With throw exception we can handle the exceptions thrown by the program itself. If a method is capable of causing an exception that it does not handle, it must specify this behavior so the callers of the method can guard against that exception.
# What is the difference between ‘Exception’ and ‘error’ in java?
Exception and Error are the subclasses of the Throwable class. Exception class is used for exceptional conditions that user program should catch. With exception class we can subclass to create our own custom exception.
Error defines exceptions that are not excepted to be caught by you program. Example is Stack Overflow.
# Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?
Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first.
# What will happen to the Exception object after exception handling?
It will go for Garbage Collection and frees the memory.
# How can you minimize the need of garbage collection and make the memory use more effective?
Use object pooling and weak object references.
# What comes to mind when you hear about a young generation in Java?
Garbage collection.
# What are Checked and UnChecked Exception?
A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses.
Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream's read() method·
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn't force client programmers either to catch the
exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method· Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.
# Use of throws exception
# What is finally in exception handling
Vector class
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment