Interview Questions and Answers for 'Exception' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Rating

   next 30
 Q31. Difference between Error and Exception ?Core Java
Ans. An Error indicates serious problems that a reasonable application should not try to catch whereas

An Exception indicates conditions that a reasonable application might want to catch.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     error  exception handling  exceptions     Asked in 2 Companies      basic        frequent


 Q32. What is Java NumberFormatException ?Core Java
Ans. NumberFormatException is the exception that Java throws when we try to convert one data type to the Number data type but the value is not parsable to be a Number.

For example , the following code will result in the NumberFormatException

String string = "Buggy";
int strtoInt = Integer.parseInt(string);

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     exceptions  NumberFormatException


 Q33. How can we catch an exception thrown by another thread ?Core Java
Ans. http://stackoverflow.com/a/6548203/2789764

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     exception handling  exception      expert        rare


Frequently asked.
 Q34. When does the finally block gets executed ?Core Java
Ans. A finally block of code always executes, whether or not an exception has occurred.The only time finally won't be called is if you call System.exit() or if the JVM crashes first.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     finally  exception handling  exceptions     Asked in 4 Companies      basic        frequent


 Q35. Can we have try statement without catch? If try statement contains return will the finally block be executed? What happens if there is an exception inside finally block?Core Java
Ans. Yes, with finally.

Yes, finally block will be executed even if there is no exception in try block.

If finally throws an exception, the exception gets thrown to the calling module.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     exception handling     Asked in 1 Companies      intermediate


 Q36. Explain Exception Hierarchy in Java SE ?Core Java
Ans. <a href="http://www.programcreek.com/2009/02/diagram-for-hierarchy-of-exception-classes/" rel="nofollow">http://www.programcreek.com/2009/02/diagram-for-hierarchy-of-exception-classes/</a>

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     exception hierarchy   exceptions     Asked in 3 Companies


 Q37. What happens to the Exception object after the exception handling is done ?Core Java
Ans. As with all other objects its garbage collected after its usage unless its rethrown.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     exceptions  exception handling        rare


 Q38. What are the fail safe systems ?Operating System
Ans. Fail Safe systems are tolerant systems that continue processing even if they sense any problem. the objective here is to continue with the processing even if there are some problems instead of completely shutting it down. Example could be to catch an exception and still letting it complete with partial results.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     fail safe systems   system design   exception handling     Asked in 3 Companies


Frequently asked at HCL Technologies ( Based on 3 feedback )
  Q39. Difference between Checked and Unchecked exceptions ?Core Java
Ans. Checked exceptions are the exceptions for which compiler throws an errors if they are not checked whereas unchecked exceptions are caught during run time only and hence can't be checked.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   checked exceptions   unchecked exceptions   exception handling   checked vs unchecked exceptions     Asked in 39 Companies      basic        frequent

Try 1 Question(s) Test


 Q40. How does a try statement determine which catch clause should be used to handle an exception?Core Java
Ans. When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exception is executed. The remaining catch clauses are ignored.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   exception handling   try   catch      basic        frequent


 Q41. Give an Example of checked and unchecked exception ?Core Java
Ans. ClassNotFoundException is checked exception whereas NoClassDefFoundError is a unchecked exception.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   checked exceptions   unchecked exceptions   exception handling     Asked in 2 Companies


 Q42. Name few Java Exceptions ?Core Java
Ans. IndexOutofBoundException ,
NoClassDefFoundException ,
OutOfMemoryException ,
IllegalArgumentException,
NullPointerException,
IllegalStateException

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   exceptions   basic interview question      basic        frequent


 Q43. How can we make sure that a code segment gets executed even in case of uncatched exceptions ?
Ans. By putting it within finally.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   exceptions   finally   uncatched exceptions      basic        frequent


 Q44. Explain java.lang.OutOfMemoryError ?Core Java
Ans. This Error is thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   jvm   outofmemoryerror     Asked in 1 Companies


 Q45. Is it necessary that each try block to be followed by catch block ? Core Java
Ans. It should be followed by either catch or finally block.

  Sample Code for Retry in case of exception

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   exception handling   try   catch   finally  Oracle OCA Test     Asked in 3 Companies      basic        frequent

Try 1 Question(s) Test


 Q46. Can finally block be used without catch ?Core Java
Ans. Yes but should follow "try" block then.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   exception handling   try   catch   finally   yes-no

Try 1 Question(s) Test


 Q47. What is exception propogation ?Core Java
Ans. Passing the exception object to the calling method.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   exception handling   throw


 Q48. When do you get ClassCastException?

or

What is ClassCastException ?
Ans. As we only downcast class in the hierarchy, The ClassCastException is thrown to indicate that code has attempted to cast an object to a subclass of which it is not an instance.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   class casting   classcastexception   exception   error     Asked in 4 Companies      intermediate        frequent

Try 2 Question(s) Test


 Q49. How would you go about debugging a NullPointerException?Core Java
Ans. Open ended Questions.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   open questions   exceptions


 Q50. How compiler handles the exceptions in overriding ?Core Java
Ans. 1)The overriding methods can throw any runtime Exception , here in the case of runtime exception overriding method (subclass method) should not worry about exception being thrown by superclass method.

2)If superclass method does not throw any exception then while overriding, the subclass method can not throw any new checked exception but it can throw any runtime exception

3) Different exceptions in java follow some hierarchy tree(inheritance). In this case , if superclass method throws any checked exception , then while overriding the method in subclass we can not throw any new checked exception or any checked exception which are higher in hierarchy than the exception thrown in superclass method

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   overriding   exceptions   inheritence   inheritance  object oriented programming (oops)  oops concepts   oops


 Q51. Difference between throw and throws ?Core Java
Ans. throw is used to explicitly throw an exception especially custom exceptions, whereas throws is used to declare that the method can throw an exception.

We cannot throw multiple exceptions using throw statement but we can declare that a method can throw multiple exceptions using throws and comma separator.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   exception handling   throw   throws   difference between   basic interview question      basic        frequent

Try 1 Question(s) Test


 Q52. What are the sub classes of Exception class?Core Java
Ans. The Exception class has two main subclasses : IOException class and RuntimeException Class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   exception class   ioexception   runtimeexception


 Q53. How finally used under Exception Handling?Core Java
Ans. The finally keyword is used to create a block of code that follows a try block. A finally block of code always executes, whether or not an exception has occurred.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   exception handling   try   finally   basic interview question     Asked in 1 Companies

Try 1 Question(s) Test


 Q54. What things should be kept in mind while creating your own exceptions in Java?Core Java
Ans. All exceptions must be a child of Throwable.

If you want to write a checked exception that is automatically enforced by the Handle or Declare Rule, you need to extend the Exception class.

You want to write a runtime exception, you need to extend the RuntimeException class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   exception handling   user defined exceptions   throwable   architecture   library development   technical architect   technical lead


 Q55. Can try statements be nested?Core Java
Ans. Yes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   try   yes no      basic


 Q56. Will finally be called always if all code has been kept in try block ?Core Java
Ans. The only time finally won't be called is if you call System.exit() or if the JVM crashes first.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   exception handling   try   catch   finally   system   system.exit


 Q57. what will be the output ?

class Animal {
public void eat() throws Exception {
}
}

class Dog2 extends Animal {
public void eat(){}
public static void main(){
Animal an = new Dog2();
an.eat();
}
}
Core Java
Ans. Compile Time Error: Unhandled exception type Exception

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   code   coding   overridding   late binding   exception handling   abstract class   abstract methods


 Q58. Can finally block throw an exception ?Core Java
Ans. Yes. Methods invoked from within a finally block can throw an exception. Failure to catch and handle such exceptions results in the abrupt termination of the entire try block.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   exception handling   finally   yes-no


 Q59. Can we have try and catch blocks within finally ?Core Java
Ans. Yes, if we have a cleanup code that might throw an exception in the finally block, then we can have a try-catch block

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   exceptions   exception handling   finally   try   catch   yesno


 Q60. Which exception should be handled in the following code ?

File file = new File("../file.txt");
FileWriter fileWriter = new FileWriter(file);
Core Java
Ans. IOException

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   io   file   fileio   coding   code   exception   ioexception  file handling


previous 30   next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: