HTML

Java 8 Default Methods FAQ - Frequently asked Questions and Answers

In last a couple of articles, I have to talk about default methods introduced in JDK 8. First, we have learned what is default method and why it is introduced in Java. Then we have seen the example of how you can use default methods to evolve your interface. After that we have analyzed does Java really support multiple inheritances now in JDK 8 (see here) and how will Java handle the diamond problem that will arise due to default methods. For example, what will happen if a class extend a class and implement an interface and both contain a concrete method with same method signature? Will a diamond problem arise? How will Java handle that and how you can solve it, and the difference between abstract class and interface in Java 8?  Once you went through those articles, you would have a good knowledge of default methods in Java 8.

Default Methods in Interface, Multiple Inheritance and Diamond Problem in Java 8

Ever since Java 8 introduced default and static methods in JDK 8, it's become possible to define non-abstract methods in interfaces and since in Java one class can implement multiple interfaces and because there can be concrete methods in interfaces, the diamond problem surfaced again. What will happen if two interface has methods o the same name and a Java class inherit from it? Many Java programmer also asks me the question that, is Java 8 is also supporting multiple inheritances of classes, as it seems because interface with methods is similar to abstract class or in that any class. Well, it’s not.

Java 8 Default Methods On Interface : What, Why and Example

Whenever someone talks about Java 8, the first thing he speaks about is lambda expression and How lambda expression will change the way you use Collections API today. In truth, lambda expression would not be that useful had language not been enhanced to support default methods on Java Interface. Also known as a virtual extension or defender methods, they allow you to declare a non-abstract method inside Java interface. Which means, finally you can add new methods without breaking all classes, which implements a certain interface. This opens a new path for enhancing and evolving existing Collection API to take advantage of lambda expressions. For example, now you can iterate over all elements of Collection in just one line, as opposed to four lines it requires you to do prior to Java 8.

Difference between Abstract class and Interface in Java 8 with Default Methods

Ever since JDK 8 has allowed concrete methods on interface e.g. default and static methods, many of my readers have asked me how should they answer the classical abstract class vs interface questions. In this post, I'll revisit this hugely popular Java interview question in light of Java 8 changes. Before JDK 8, the level of abstraction was the clear cut difference between abstract class and interface i.e. interface was the purest form of abstraction which only define what interface is supposed to do without specifying how i.e. it only declare API methods and leave implementation to its subclasses.  All methods of an interface were abstract but since Java 8 you can define non-abstract methods in form of default and static methods inside interface in Java.

Top 5 Free Spring Certification Mock Exams and Practice Questions

Many Java developers don't know that similar to Oracle's Java certification, there is also a Spring certification program, which certifies yourself for your Spring framework skill. There are three Spring certifications currently available, Spring Professional certification exam, which certifies on your general knowledge about Spring framework, Spring Web Application Developer exam, which certifies you about your Spring MVC skill and Spring Enterprise Integration Specialist certification exam, which is for advanced Spring Integration skill. Earlier, SpringSource provides this company but now they are provided by Pivotal, the company behind Spring framework.