Core Java - Interview Questions and Answers for 'Interface' | 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

   



Core Java - Interview Questions and Answers for 'Interface' - 68 question(s) found - Order By Rating

next 30
 Q1. What is concurrent interface ?Core Java
Ans. ConcurrentMap is an interface and it is a member of the Java Collections Framework. It represents a Map that is capable of handling concurrent access to it without affecting the consistency of entries in a map. ConcurrentMap interface present in java.util.concurrent package.

HashMap operations are not synchronized, while Hashtable provides synchronization. Though Hashtable is thread-safe, it is not very efficient. To solve this issue, the Java Collections Framework introduced ConcurrentMap in Java 1.5.

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

   Like         Discuss         Correct / Improve     Concurrent Interface   java.util.concurrent   Java 8 Concurrency   java concurrency   java 8     Asked in 1 Companies


 Q2. Explain interfaces in Typescript. How is it different compared to other languages ?TypeScript
 This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     interfaces in typescript


 Q3. Interface vs AbstractionCore Java
 This question was recently asked at 'Oracle financial services'.This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     interface vs abstraction  interfacing vs abstraction  relation between interface and abstraction  How interface provide abstraction     Asked in 1 Companies


 Q4. What will happen if there are no interfaces in Java ?Core Java
Ans. Abstract classes can take care of that to a certain extent. Though they are little heavier than Interfaces but An abstract class with all abstract methods and no instance variables will be able to help with everything that currently an interface does.

The only problem is that a class can only extend one class whereas it can implements multiple interfaces and that is the reason Interfaces were introduced in Java, i.e to get over the problem of multiple inheritance.

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

   Like         Discuss         Correct / Improve     interfaces      expert


 Q5. Which Java version supports Interface Default methods ?Core Java
Ans. Java 1.8 or Java 8

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

   Like         Discuss         Correct / Improve     default methods   interface default methods   java 8  java 8 features


 Q6. Does Java generate .class file for interfaces ? Core Java
Ans. Yes

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

   Like         Discuss         Correct / Improve     .class file  java byte code  interfaces


 Q7. Can we declare constructor inside an interface ? Why ?Core Java
 This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     interface   constructor


 Q8. Can we have interface as a replacement for utility class ? Core Java
Ans. Yes, With Java 8 we can use Interfaces as collection of utility methods through the use of default methods.

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

   Like         Discuss         Correct / Improve     java 8  interfaces  utility class   utility classes


 Q9. How do you define a functional interface?Core Java
Ans. Create interface with the only one non-overriding abstract method and annotate it with @FunctionalInterface

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

   Like         Discuss         Correct / Improve     functional interface  java 8     Asked in 1 Companies


 Q10. What is an Interface ?Core Java
Ans. The interface is a mechanism to achieve abstraction. Interfaces can have abstract methods and variables. It cannot have a method body.

  Sample Code for interface

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

   Like         Discuss         Correct / Improve     interface     Asked in 1 Companies      basic        frequent


 Q11. Why do we use Thread Class as well as Runnable Interface for creating threads in Java ?Core Java
 This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     Threads  Thread class  runnable interface


 Q12. What are the advantage of Abstract classes over interfaces with respect to Java 7 ? and What changed in Java 8 to help facilitate that in Java 8 ?Core Java
Ans. Abstract Classes provide default implementations of methods that are inherited by the classes that extend them, which was not the case for Interfaces. This changed in Java 8, where default implementations are provided for methods.

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

   Like         Discuss         Correct / Improve     abstract classes  interfaces  default method     Asked in 1 Companies      expert


 Q13. Why can't we have diamond problem with interfaces ?Core Java
Ans. Interfaces don't have member elements and method definitions that could cause diamond problem. With Java 8, Interfaces have default method definitions. This could have created diamond problem but Java introduced a compile time check for "duplicate default methods" in case same method is derived from multiple interfaces and no definition is overridden by the class.

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

   Like         Discuss         Correct / Improve     diamond problem  interfaces  java 8  default methods


 Q14. Can an interface implements another interface ?Core Java
Ans. No. No interface provides any implementation and hence the declaration isn't viable.

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

   Like         Discuss         Correct / Improve     interface      basic


 Q15. Can an interface be defined inside a class just like we can have inner classes inside a class ?Core Java
Ans. Yes , we can have an interface that is part of a class.

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

   Like         Discuss         Correct / Improve     inner classes   inner interface  nested classes


 Q16. If an Abstract class has only abstract methods, What's the difference between such a class and an interface ?Core Java
Ans. Such a class still can have member elements which can be inherited and hence facilitate code reuse. Moreover Abstract class can have non final static elements whereas interfaces are only allowed to have static final elements.

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

   Like         Discuss         Correct / Improve     abstract class   interfaces     Asked in 2 Companies      Basic


 Q17. What are the core interfaces of Spring mvc ?Spring
 This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     core interfaces of Spring mvc


 Q18. What are the core interfaces in Hibernate?Hibernate
Ans. Session,SessionFactory,Configuration,Transaction,query and Criteria

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

   Like         Discuss         Correct / Improve     core interfaces of Hibernate     Asked in 1 Companies        frequent

Try 1 Question(s) Test


 Q19. What are the types of Executor Interfaces ?Core Java
Ans. Executor - Simple Interface that supports launching new tasks.

ExecutorService - Subinterface of Executor, which adds features that help manage the lifecycle, both of the individual tasks and of the Executor itself.

ScheduledExecutorService - Subinterface of ExecutorService, supports future and-or periodic execution of tasks.

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

   Like         Discuss         Correct / Improve     Executor Interfaces     Asked in 1 Companies


 Q20. How Marker interfaces works internally ?Core Java
 This question was recently asked at 'GGK Technologies'.This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     marker interfaces  interfaces     Asked in 1 Companies      expert        rare


 Q21. What will be the output of following code ?

Base Interface

public interface BaseInterface {
   int i = 4;
}

Derived Interfaces

public interface DerivedInterface1 extends BaseInterface{
   int i = 5;
}

public interface DerivedInterface2 extends BaseInterface{
   int i=6;
}

Implementing Class

public class Class implements DerivedInterface1,DerivedInterface2 {
int i=10;   

public static void main(String[] args){
      System.out.println(new Class().i);
   }
}

What will be the output upon executing main and Why ?
Core Java
Ans. 10

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

   Like         Discuss         Correct / Improve     interfaces  coding  code      intermediate


 Q22. What will be the output of following code ?

Base Interface

public interface BaseInterface {
   int i = 4;
}

Derived Interfaces

public interface DerivedInterface1 extends BaseInterface{
   int i = 5;
}

public interface DerivedInterface2 extends BaseInterface{
   int i=6;
}

Implementing Class

public class Class implements DerivedInterface1,DerivedInterface2 {
   public static void main(String[] args){
      System.out.println(BaseInterface.i);
   }
}

What will be the output upon executing main and Why ?
Core Java
Ans. It will print 4 because member elements of an interface are implicitly static and hence the concept of overriding doesn't work.


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

   Like         Discuss         Correct / Improve     interfaces  coding  code  extending interfaces  diamond interfaces     Asked in 1 Companies      intermediate


 Q23. What is nested interface?Core Java
Ans. Interface that is declared inside the interface or class, is known as nested interface. It is static by default.

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

   Like         Discuss         Correct / Improve     interface  nested interface      intermediate

Try 1 Question(s) Test


 Q24. Can we have an inner class within Interface ?Core Java
Ans. Yes, we can define an inner class within interface.Inside the interface, the inner class is implicitly public static.

So the following is legit in Java

public interface BuggyBreadInterface {
   void doSomething();

   public class BuggyBreadClass implements BuggyBreadInterface{
      void doSomething(){
         System.out.println("Do something");
      }
   }
}

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

   Like         Discuss         Correct / Improve     inner classes  inner class in interface  nested classes


 Q25. Which is the root interface of Collection classes in Java ?Core Java
Ans. java.util.Collection

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

   Like         Discuss         Correct / Improve     collection interface  collections


 Q26. Why Collection interface does not extend Cloneable interface ?Core Java
Ans. Here is the list of classes that implements Collections Interface - http://www.buggybread.com/2015/02/java-collections-classes-that-implement.html

Having Collection interface to extend Cloneable interface would mean necessarily implement clone method by all implementing classes. As not all collection classes allow duplicate elements, it makes no sense to clone elements for them.

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

   Like         Discuss         Correct / Improve     cloneable  collections  collection interface  cloning


 Q27. Where do we generally use comparable interface ?Core Java
Ans. Implementing Comparable interface means that the elements of the class are comparable i.e the class provides the implementation of compareTo method that would help comparing the elements.

This is usually required if we are planning to sort elements of a collection, If compareTo method is not defined , the sorting class / method could never understand a way to compare its elements in order to sort them.

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

   Like         Discuss         Correct / Improve     comparable interface

Try 1 Question(s) Test


 Q28. Do we need to implement all interface methods if a class is implementing it ?Core Java
Ans. Yes, a Class is supposed to define all abstract methods declared in the interface. With Java 8 , Interfaces can have default methods which need not be implemented by the implementing class.

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

   Like         Discuss         Correct / Improve     interfaces


 Q29. Does default methods introduce multiple inheritance and the Diamond problem in Java 8 ?Core Java
Ans. Default methods results in multiple inheritance of behavior and not of state. In case we try to implement multiple interfaces with default method having same name and signature, and don't override it in implementation class, it will throw an error.

For example -

interface MyInterface {
public void default myMethod(){
}
}

interface MyInterface2 {
public void default myMethod(){
}
}

class MyClass implements MyInterface,MyInterface2 {
}

This code will compilation error "Duplicate Default Method"

if we specify the definition of myMethod() in myClass, compiler won't complain and there is no conflict and MyClass can use overridden definition. But if we don't override myMethod() in MyClass, Java would be in conflict as to what definition should be carried to MyClass and hence throws compilation error.

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

   Like         Discuss         Correct / Improve     default methods  java 8  multiple inheritance  object oriented programming (oops)  oops concepts  diamond problem   interfaces


 Q30. What are the different uses of Interfaces in Java ?Core Java
Ans. 1. Regulation / Enforcement / Policy / Contract , It's primary use

2. Use as a collection of utility methods(since java 8 through default methods)

3. Collecting constants together, As Interface are lighter, it makes sense to use them instead of classes if no getters and setters required.

4. Creation of Custom Annotations

5. Special services like marker interface

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

   Like         Discuss         Correct / Improve     interfaces   uses of interfaces in java     Asked in 1 Companies


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: