Skip to main content

Top 25 Java Question for a Experinced Candiates with answers


1)What are the Java 8 Features in java?

      *For Each() method in Iterable Interface.
      *Default and Static methods in interface.
      *Functional Interface and Lambada Expression.
      *Collection API Improvements.

 NOTE: We can use default and static keyword to create Interface with Implementation.

2)Define a Concrete Class?

    *used for Specific Requirement.
    *Object of Concrete Class can be created directly
   *Containing fully defined methods or implementation methods.

3)Steps for remove duplicates elements in java?

    public class RemoveDuplicates
       
           {
                ArrayList<object> a1= new ArrayList<object>();
                al.add("JAVA"); //you can add any number of the data you want
             
                     System.out.println("the elements are:" +a1);
                   
                       for(int i=0; i<a1.size(); i++)
                             {
                                  if(a1.get(i).equals(a1.get(j)))
                                    {
                                        a1.remove(j);
                                        j--;
                                     } 
                                 }
                         }
           System.out.println("After Removing the duplicates elements:" +a1 );

      }
}


4) Define halt() function?
         public void halt(int staus):
                           Forcibly terminates the currrently running JVM.
                           This method never returns normally.
                         
5) exit() function;
            public void exit(int status):
                           This method terminates the currently running Java Virtual Machine.
                     java.lang.sysyem.exit();
             

6)Do all properties of an Immutable Object need to be final?

              Not necessary no need make all the object as a final, you can achieve the same functionality by making the member non-final but non-private and not modifying them except in the constructor.


7)How does the substring() method inside String works?

                           A string is supported by a char array in the back-end. They are used to store real character array, the first index of the array, the number of characters in the String. When the substring() method is called, it creates a new string, but the string's value still points to the same array in the heap. A String is used for the characters and cann't be changed once declared and it is used for a security puropose.




8) 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

9)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.

10)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.

11)Define covariant return type?
          The covariant return type specifies that the return type may vary in the same direction as the subclass.

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

13)What is Encapsulation?

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


14)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:

  1. Checked Exception
  2. Unchecked Exception
  3. Error

15)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.

16)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.

17)Define Error?

            It is irrecoverable. This mistake was done by user and can't be solved.
    eg: outofmemoryerror.  

18)How can we handled a Exception?


      We can handle Exception by using a try and catch block.

19)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.

20)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.

21)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.

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

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

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

26) 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();
             }        
        









Comments

Popular posts from this blog

Commonly asked Top 26 Java Interview Questions

1.what is a transient variable? A transient variable is a variable that may not be serialized. If you don't want to serialize any objects then we have to use Transient Keyword. 2. Why do threads block on I/O? Threads block on i/o (that enters the waiting state) so that other threads may execute while the i/o Operation is performed. So your blocked thread of execution blocks only that: the thread of execution. 3. How are Observer and Observable used? Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects(refer 1.4). 4. What is synchronization and why is it important?                      With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Withou

All difference Question in java(common difference) (Collections)

1)Difference Between Interfaces And Abstract class? All the methods declared in the Interface are Abstract,where as abstract class must have atleast one abstract method and others may be concrete. In abstract class keyword abstract must be used for method, where as in Interface we need not use the keyword for methods. Abstract class must have Sub class, where as Interface can’t have sub classes.  An abstract class can extend only one class, where as an Interface can extend more than one. 2)Difference between Arrays and Vectors?             Because Vectors are dynamically-allocated, they offer a relatively memory-efficient way of handling lists whose size could change drastically. Arrays are fixed in size and it's wastage of memory problem. A Vector might be a good choice for such an arrangement. Moreover, Vectors have some useful member functions that make coding simpler. While in array is the bad choice of the arrangement and the code become more complex. Vecto

Decode of the image file from hibernate and struts

Create a java file for the decoding the image Image.java package com.img.action; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.imageio.ImageIO; import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext; import com.img.dao.ConnectionDAO; import com.img.pojo.Film_TablePojo; import com.img.pojo.imagePojo; import com.opensymphony.xwork2.ActionSupport; public class Show extends ActionSupport { List<Object> values = new ArrayList<Object>();  public List<Object> getValues() { return values; } public void setValues(List<Object> values) { this.values = values; } /*HttpServletRequest request;     public void setServletRequest(HttpServletRequest