There is given a list of exception handling interview questions with answers. If you know any exception handling interview question, kindly post it in the comment section.java
Exception Handling is a mechanism to handle runtime errors.It is mainly used to handle checked exceptions.swift
The classes that extend Throwable class except RuntimeException and Error are known as checked exceptions e.g.IOException,SQLException etc. Checked exceptions are checked at compile-time.post
The classes that extend RuntimeException are known as unchecked exceptions e.g. ArithmeticException,NullPointerException etc. Unchecked exceptions are not checked at compile-time.ui
more details...google
Throwable.spa
It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block OR a finally block. And whatever exceptions are likely to be thrown should be declared in the throws clause of the method.code
finally block will not be executed if program exits(either by calling System.exit() or by causing a fatal error that causes the process to abort).more details...ip
throw keyword | throws keyword |
---|---|
1)throw is used to explicitly throw an exception. | throws is used to declare an exception. |
2)checked exceptions can not be propagated with throw only. | checked exception can be propagated with throws. |
3)throw is followed by an instance. | throws is followed by class. |
4)throw is used within the method. | throws is used with the method signature. |
5)You cannot throw multiple exception | You can declare multiple exception e.g. public void method()throws IOException,SQLException. |
Yes.
Yes but only unchecked exception not checked.
Forwarding the exception object to the invoking method is known as exception propagation.
There is given a list of string handling interview questions with short and pointed answers. If you know any string handling interview question, kindly post it in the comment section.
The simple meaning of immutable is unmodifiable or unchangeable. Once string object has been created, its value can't be changed.
Because java uses the concept of string literal. Suppose there are 5 reference variables,all referes to one object "sachin".If one reference variable changes the value of the object, it will be affected to all the reference variables. That is why string objects are immutable in java.
There are two ways to create the string object, by string literal and by new keyword.
Only one object.
To make Java more memory efficient (because no new objects are created if it exists already in string constant pool).
Two objects, one in string constant pool and other in non-pool(heap).
String is an immutable object. StringBuffer is a mutable object.
StringBuffer is synchronized whereas StringBuilder is not synchronized.
We can create immutable class as the String class by defining final class and
The toString() method returns the string representation of any object. If you print any object, java compiler internally invokes the toString() method on the object. So overriding the toString() method, returns the desired output, it can be the state of an object etc. depends on your implementation.
A class which is declared inside another class is known as nested class. There are 4 types of nested class member inner class, local inner class, annonymous inner class and static nested class.
Yes, inner classes are non-static nested classes i.e. inner classes are the part of nested classes.
No, local variable must be constant if you want to access it in local inner class.
Any interface i.e. declared inside the interface or class, is known as nested interface. It is static by default.
Yes, it is known as nested interface.
Yes, they are static implicitely.