Thursday, 3 May 2018

Top Most Java Question That are asked in the interview

1) what is method overloading in java?

     *A class has a multiple methods with a same name but with different parameters.

Advantage: 

*It will increases the readability of the program.


Two ways to overload the method:

  • By changing number of arguments
  • By changing the data type


2)Why method overloading is not possible to change the return type of the method?
           It is not possible to change the return type because it cause a ambitguity problem.

3)what is method overridding?

    * If the name of the method in the subclass(child class) and super class(parent class) are same name then it is called as a overridding.
 * It is a runtime polymorphism.

4)Define covariant return type?

          The covariant return type specifies that the return type may vary in the same direction as the subclass.

5)What is a final keyword?
    *Final keyword is used to restrict the user.
    *Final keyword can used in 
          *class
          *variable 
           *method

6)What is Encapsulation?

   It is process of wrapping code and data together into a single unit.
It provides control over the data.

7)Define Exception handling in java?

*Exception handling in java is one of the powerful mechanism to handle the runtime errors so that normal flow of the application can be maintained.

*Exception is an abnormal condition.

*Exception Handling is a mechanism to handle runtime errors such as ClassNotFound etc.

Types of Exception:

  • Checked Exception
  • Unchecked Exception
  • Error

8)Define Checked Exception?

    * 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.

9)Define Unchecked Exception?

           Classes that extend RuntimeException are known as unchecked exceptions e.g. ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException etc. 

*Unchecked exceptions are not checked at compile-time rather they are checked at runtime.

10)Define Error?
            It is irrecoverable. This mistake was done by user and can't be solved.
    eg: outofmemoryerror.  

11)How can we handled a Exception?
      We can handle Exception by using a try and catch block.

12)What is a Finallay block?
           *It is used to executed the important code such as closing a connection.
           *finally block always executed whether exception is handled or not.

13)What is Finalize?
      It is used to perform clean up processing just before object garbage is collected.
      It is used to remove the unwanted memory space.

14)what is collection in java?

      *A collection is represent a collection of a objects into the single unit.
      *A collection is a unified architecture for storing and manipulating a  objects.

    *It is set of a classes and interface.

15) what are the types of  the collections?
     *List :
               Arraylist
               Linked List
               Vector
     *Set
              Hashset
              LinkedHashSet
              SortedSet
   *Queue
              Deque
              ArrayDeque

16)Define Enum?
              *Enum is define as a set of date and time.
               
17)Define Constructor?
           Constructor is same as a class name and used to initialize the object ant the time of the object creation.

18)Define Abstraction?
           Abstraction is used to hide the unwanted details and showing only functionality to the user.
         Abstract(0 to 100%)
         interface(100%)

19) Define Interface?

           All unwanted implementation are called as a interface.
     Interface can be declared as by using a name interface.   
      ex: 
          interface Date
           {
               void run();
                void display();
             }