Home
31.
what are the categories of exceptions ?

Exceptions are divided into three categories. That are checked exceptions, runtime or unchecked exceptions and errors.

32.
Tell me few about checked exceptions ?
  • A checked exception is an unacceptable condition foreseen by the author of a method, but outside the immediate control of the code.
  • FileNotFoundException is a checked exception. This exceptions is thrown if the file that the code is trying to access can't be found.
  • If a method calls another method that may throw a checked exception, either it must be enclosed within a try-catchblock or the method should declare this exception to be thrown in its method signature.
33.
Tell me few about runtime exceptions ?
  • Runtime exceptions represent programming errors. These occur from inappropriate use of another piece of code. For example, NullPointerExceptionis a runtime exception that occurs when a piece of code tries to execute some code on a variable that hasn't been assigned an object and points to null. Another example is ArrayIndexOutOfBoundsException, which is thrown when a piece of code tries to access an array of list elements at a nonexistent position
  • A runtime exception is a subclass of java.lang.RuntimeException.
  • A runtime exception isn't a part of the method signature, even if a method may throw it.
  • A runtime exception may not necessarily be caught by a try-catch block
  • 34.
    What is the use of continue statement ?

    The continuestatement is used to skip the remaining steps in the current iteration and start with the next loop iteration.

    35.
    Tell me few abouts Objects Lifecycle.
    • An object's lifecycle starts when it's initialized and lasts until it goes out of scope or is no longer referenced by a variable.
    • When an object is alive, it can be referenced by a variable and other classes can use it by calling its methods and accessing its variables.
    • Declaring a reference object variable isn't the same as creating an object.
    • An object is marked as eligible for garbage collection when it can no longer be accessed.
    • we can be sure only about whether objects are marked for garbage collection. we can never be sure about whether an object has been garbage collected.