Explore Default Method in JAVA 8 & Crack few challenges
Today, let's explore the one of new feature of java 8 "DEFAULT METHOD".
Here, I am not going to give you complete theory about this new concept as it's well explained @here
So, instead of that, let's play and focus on, how would you code simple program with this default method concept and see what kind of issues you raised while working with you current eclipse IDE :)
I have an eclipse kepler IDE and i installed java 8 from oracle site here
Now i coded below very simple program using concept of interface,concrete class and main test programm.
In the IProgramming interface, you can see my default method getAuthorName() but i am not able to compile it and getting error message in interface level and even in implemented class level too.(please check error message in above code snippet)
So ,What ? I can't run and see output of my main test program..and i want to resolve it ..
and i reviewed and checked my java setting and compiler level for this program in eclipse.
Very Good, I excited as JRE 8 were set properly...
So, let me check compiler setting, do you know where is it ? in eclipse :) don't bother, have look it below
OMG, I saw that my compiler setting option is upto 1.7 java version and this new concept feature in only available in java 8 so i can't manage to run it using this setting :)
What to do ?
Don't bother, you can see the issue is only due to this crazy issue so finally i have able to manage it to get compiler setting for 1.8 java.
and now what, you can see my code is look compatible with java 8 and can't see error message in eclipse IDE
Also, I finally ...run my program from this eclipse IDE and got expected output in Console window ...check above result if you did not notice it ..
Enjoy and have nice weekend ...
Bye and keep learning ..
Comments