JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

Java-8: Interface with default methods vs Abstract class.


Answer:

After introducing Default Method, it seems that interfaces and abstract classes are same. However, they are still different concept in Java 8.

Abstract class can define constructor. They are more structured and can have a state associated with them. While in contrast, default method can be implemented only in the terms of invoking other interface methods, with no reference to a particular implementation's state. Hence, both use for different purposes and choosing between two really depends on the scenario context.

Default methods in Java interface enables interface evolution. Given an existing interface, if you wish to add a method to it without breaking the binary compatibility with older versions of the interface, you have two options at hands: add a default or a static method. Indeed, any abstract method added to the interface would have to be implemented by the classes or interfaces implementing this interface.

A static method is unique to a class. A default method is unique to an instance of the class. If you add a default method to an existing interface, classes and interfaces which implement this interface do not need to implement it.

<< Previous Question | Next Question >>

List Of Java Interview Questions:

  1. Previous set of java interview questions
  2. What is difference between Lambda Expression and Anonymous class?
  3. What is HTTP basic authentication?
  4. What is functional interface in java?
  5. What is the difference between HTTP methods GET and POST?
  6. What is difference between CountDownLatch and CyclicBarrier in Java?
  7. Can Enum extend any class in Java?
  8. Can Enum implements any interface in Java?
  9. Can we have constructor in abstract class?
  10. What is MVC pattern?
  11. What is ActionServlet in struts?
  12. What is the difference between servlet & Filter?
  13. What is ActionMapping in struts?
  14. What is the difference between application server and web server?
  15. What is the difference between JPA and Hibernate?
  16. What is difference between the Value Object and JDO?
  17. How Struts control data flow?
  18. What is Spring?
  19. What is Dependency Injection?
  20. What are the different types of dependency injections in spring?
  21. What is BeanFactory in Spring?
  22. What is difference between BeanFactory and ApplicationContext in spring?
  23. How to make a bean as singleton in spring?
  24. What is IOC or inversion of control?
  25. What are different types of spring auto-wiring modes?
  26. What are the limitations and disadvantages of spring autowiring?
  27. Is the spring singleton bean thread safe?
  28. Why ConcurrentHashMap is faster than Hashtable in Java?
  29. What is the difference between ConcurrentHashMap and Hashtable in Java?
  30. Difference between ConcurrentHashMap and Collections.synchronizedMap(Map)?
  31. What is the difference between ORM, JPA and Hibernate?
  32. What is stream pipelining in Java 8?
  33. What is interface default method in java 8?
  34. Java-8: Interface with default methods vs Abstract class.
  35. What is @SpringBootApplication annotation in Spring boot project?
  36. What Embedded Containers Does Spring Boot Support?
  37. What are the advantages and disadvantages of Spring Boot?
  38. What is Spring Boot Actuator?
  39. What is Spring Boot Initializr?
  40. How does Maven resolve version conflicts of dependencies?
  41. How to reload Spring Boot Application without restarting server?
  42. What is the difference between Spring Boot and the Spring framework?
  43. What are the key components of Spring Boot framework?
  44. What are the different types of bean scope in Spring framework?
  45. What are the standard Spring build-in events?
  46. What is Spring IoC container?
  47. Differences between BeanFactory and the ApplicationContext in Spring framework.
  48. Difference between constructor injection and setter injection in Spring.
  49. How Java-8 Streams differ from collections
  50. What are the various ways to obtain Streams in Java-8?
  51. List Java-8 Streams intermediate operations.
  52. List Java-8 Streams terminal operations.
  53. Can we reuse Java-8 Streams?
  54. Difference between map and flatMap methods in Java 8
  55. What is the difference between Closure and Lambda in Java 8?
  56. Does Java 8 Lambda supports recursive call?
  57. Can Java 8 default methods override equals, hashCode and toString?
  58. Hibernate Eager vs Lazy Fetch Type
  59. What is POJO?
  60. What is HQL (Hibernate Query Language)?
Knowledge Centre
doPost Vs doGet methods
doGet() method is used to get information, while doPost() method is used for posting information. doGet() requests can't send large amount of information and is limited to 240-255 characters. However, doPost()requests passes all of its data, of unlimited length. A doGet() request is appended to the request URL in a query string and this allows the exchange is visible to the client, whereas a doPost() request passes directly over the socket connection as part of its HTTP request body and the exchange are invisible to the client.
Famous Quotations
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2022 by Nataraja Gootooru. All Rights Reserved.