Link Search Menu Expand Document

Intermediate Java Interview Questions

Are you preparing for your Java interview? Need to brush up your command over Java? Here are 9 questions that will help you give insight into the workings of Java.

Q1. What are the names of Java IDE’s?

Ans. There are two Java IDE’s whose names are Eclipse and NetBeans.

Q2. What does constructor mean?

Ans. To initialize the objects, we use a constructor. According to the class of the object created, a constructor is called. The class name and the constructor name must be similar; otherwise, a default constructor is created. The constructor can eventually be overloaded. The user can create a constructor with a defined parameter; however, a constructor must be created without a parameter.

Q3. What is the difference between Local Variable and Instance Variable?

Ans. In Java, a local variable means any variable that has been mentioned within a method. That limits the possibilities of that variable within its defined boundaries. An instance method is defined outside the body of the method, constructor, etc. but within a class. Thus, it can be accessed by the whole class.

Q4. Define class?

Ans. A class acts as the plan, which helps in creating objects. It arranges everything in a sequence with the help of a user, all the variables and methods. The variables store the data of a class within themselves and define its state. The instructions are stored in methods.

Q5. What does inheritance mean?

Ans. Inheritance in Java is a concept that tells that one class can extend itself to another class, which improves the efficiency of the class as one code can be used to another class.

Q6. What is polymorphism?

Ans. Polymorphism is related to inheritance in Java. The name itself suggests that many classes are attached to each other. A single object thus possesses a superclass and a subclass. Polymorphism uses those methods to initiate different tasks.

For example:
Public class Manipulation(){ //Super class
public void add(){
}
}
public class Addition extends Manipulation(){ // Sub class
public void add(){
}
public static void main(String args[]){
Manipulation addition = new Addition();//Manipulation is reference type and Addition is reference type
addition.add();
}
}

Q7. State the differences between HashSet and TreeSet?

Ans. HashSet set doesn’t require the elements to be inserted in a particular order. It stores null objects within and enables the performance overall to be very fast. TreeSet, on the other hand, performs very slow, is unable to store the null objects, and requires the elements to be in a particular order.

Q8. Difference between Abstract class and Interface?

Ans. An abstract class has a default constructor which is invoked at the time a subclass instantiates.  It has both abstract and non-abstract methods. Only the abstract methods are required to be implemented in the subclass and don’t require other methods while extending for the class to an abstract class. They also have instance variables. On the other hand, Interface doesn’t have any constructor; thus, it can’t be instantiated. The abstract method has to be declared in isolation here. The interface requires implementation from the classes, which provides the implementation for other methods as well. Here, no instance variables are present but only constants.

Q9. What does collection mean in Java?

Ans. Collection in java provides a blueprint where the object is stored and modified. It has a set of functions to perform, like searching, sorting, manipulating, inserting, and deleting. Also, a group of objects comprising a single unit is known as collections.

Java is an extremely versatile application to use and is still to date has remained popular among the coders.

Other useful articles:


Back to top

© , Java Interviews — All Rights Reserved - Terms of Use - Privacy Policy