Saturday, November 29, 2014

Java Configuration API - Java 7 or Java 8 ?

Java 7 vs Java 8 for Apache Tamaya Config

Since the Apache mailing list is preventing me at all cost my more comprehensive addition to the current Tamaya discussion about Java 7 vs. Java 8, I now decided to write a blog.

I will shortly show here a small example how a modern configuration API written in Java 8 significantly differs from one written in Java 7 and why it is worth to do it in Java 8, so read ahead:


  1. the target is to build a modern API.
  2. there are many developers that do not use Spring or other technologies, where adoption is much faster.
  3. Wildfly as well as Weblogic 12.1.3 are Java 8 certified AFAIK (to be verified, since EE7 TCK does not run on Java 8...)
  4. Adoption within one year will be great.
  5. Java 8 is more than Lambdas and streams!
  6. Java 8 is the future! And we design for the future, we do not want to be one additional config framework.
  7. We can still provide a backport for Java 7. The core of Tamaya will be quite small. It should be possible to provide a backport within a couple of hours.

I give you an example here, e.g. let us start on the PropertyProvider:


In Java 8:


public interface PropertyProvider {


   Optional<String> get(String key);
   boolean containsKey(String key);
   Map<String, String> toMap();
   MetaInfo getMetaInfo();


   default boolean hasSameProperties(PropertyProvider provider) {...}
   default Set<String> keySet(){...}
   default ConfigChangeSet load(){...}
   default boolean isMutable(){...}
   default void apply(ConfigChangeSet change){...}
}


In Java 7:


With Java 7 this would be (to provide similar comfort, but on the cost of implementation dependencies and limited flexibility because of missing behavioural inheritance):


public interface PropertyProvider {


   String get(String key); // @throws ConfigException if no value
   String getOrDefault(String key, String value);


   boolean containsKey(String key);
   Map<String, String> toMap();
   MetaInfo getMetaInfo();


   default boolean hasSameProperties(PropertyProvider provider) {...}
   default Set<String> keySet(){...}
   default ConfigChangeSet load(){...}
   default boolean isMutable(){...}
   default void apply(ConfigChangeSet change){...}
}


protected abstract class AbstractPropertyProvider implements PropertyProvider {
   public boolean hasSameProperties(PropertyProvider provider) {...}
   public Set<String> keySet(){...}
   public ConfigChangeSet load(){...}
   public boolean isMutable(){...}
   public void apply(ConfigChangeSet change){...}
}


Example 2: Configuration


Looking at Configuration and the singleton access there things get even worse:


In Java 8:


public interface Configuration extends PropertyProvider{


   <T> Optional<T> get(String key, Class<T> type);
   void addPropertyChangeListener(PropertyChangeListener l);
   void removePropertyChangeListener(PropertyChangeListener l);


   default OptionalBoolean getBoolean(String key){... }
   default OptionalInt getInteger(String key){... }
   default OptionalLong getLong(String key){... }
   default OptionalDouble getDouble(String key){...  }
   default <T> Optional<T> getAdapted(String key, PropertyAdapter<T> adapter){... }
   default Set<String> getAreas(){... }
   default Set<String> getTransitiveAreas(){... }
   default Set<String> getAreas(final Predicate<String> predicate){... }
   default Set<String> getTransitiveAreas(Predicate<String> predicate){... }
   default boolean containsArea(String key){... }
   default Configuration with(ConfigOperator operator){... }
   default <T> T query(ConfigQuery<T> query){...}
   default String getVersion(){...}


   public static boolean isDefined(String name){...}
   public static <T> T of(String name, Class<T> template){...}
   public static Configuration of(String name){...}
   public static Configuration of(){...}
   public static <T> T of(Class<T> type){... }
   public static void configure(Object instance){... }
   public static String evaluateValue(String expression){... }
   public static String evaluateValue(Configuration config, String expression){...  }
   public static void addGlobalPropertyChangeListener(PropertyChangeListener listener){... }
   public static void removeGlobalPropertyChangeListener(PropertyChangeListener listener){...}
}


In Java 7:


public interface Configuration extends PropertyProvider{
   <T> T get(String key, Class<T> type); // throws ConfigException
   <T> T getOrDefault(String key, Class<T> type, T instance);
   void addPropertyChangeListener(PropertyChangeListener l);
   void removePropertyChangeListener(PropertyChangeListener l);


   boolean getBoolean(String key){... } // throws ConfigException
   boolean getBooleanOrDefault(String key, boolean defaultVal){... }
   int getInteger(String key){... } // throws ConfigException
   int getIntegerOrDefault(String key, int defaultVal){... } 
// throws ConfigException
   long getLong(String key){... } // throws ConfigException
   long getLongOrDefault(String key, long defaultVal);
   double getDouble(String key){... } // throws ConfigException
   double getDoubleOrDefault(String key, double defaultVal);
   <T> getAdapted(String key, PropertyAdapter<T> adapter){... } 
// throws ConfigException
   <T> getAdaptedOrDefault(String key, PropertyAdapter<T> adapter, T defaultVal){... } // throws ConfigException
   Set<String> getAreas(){... }
   Set<String> getTransitiveAreas(){... }
   Set<String> getAreas(final Predicate<String> predicate){... }
// Duplicate predicate class, or introduce additional interface
   Set<String> getTransitiveAreas(Predicate<String> predicate){... } 
// Duplicate predicate class, or introduce additional interface
   boolean containsArea(String key){... }
   Configuration with(ConfigOperator operator){... }
   <T> T query(ConfigQuery<T> query){...}
   String getVersion(){...}
}


public final class ConfigManager{
  private ConfigManager(){}


   public static boolean isDefined(String name){...}
   public static <T> T of(String name, Class<T> template){...}
   public static Configuration of(String name){...}
   public static Configuration of(){...}
   public static <T> T of(Class<T> type){... }
   public static void configure(Object instance){... }
   public static String evaluateValue(String expression){... }
   public static String evaluateValue(Configuration config, String expression)
{... }
   public static void addGlobalPropertyChangeListener(
PropertyChangeListener listener){... }
   public static void removeGlobalPropertyChangeListener(
PropertyChangeListener listener){...}
}


protected abstract class AbstractConfiguration extends AbstractPropertyProvider implements Configuration{
   boolean getBoolean(String key){... } // throws ConfigException
   boolean getBooleanOrDefault(String key, boolean defaultVal){... }
   int getInteger(String key){... } // throws ConfigException
   int getIntegerOrDefault(String key, int defaultVal){... } // throws ConfigException if not found
   long getLong(String key){... } // throws ConfigException
   long getLongOrDefault(String key, long defaultVal);
   double getDouble(String key){... } // throws ConfigExceptio
   double getDoubleOrDefault(String key, double defaultVal);
   <T> getAdapted(String key, PropertyAdapter<T> adapter){... } 
// throws ConfigException
   <T> getAdaptedOrDefault(String key, PropertyAdapter<T> adapter, T defaultVal)  
{...} // throws ConfigException
   public Set<String> getAreas(){... }
   public Set<String> getTransitiveAreas(){... }
   public Set<String> getAreas(final Predicate<String> predicate){... }
   public Set<String> getTransitiveAreas(Predicate<String> predicate){... }
   public boolean containsArea(String key){... }
   public Configuration with(ConfigOperator operator){... }
   public <T> T query(ConfigQuery<T> query){...}
   public String getVersion(){...}
}


And even when looking from the client side:


Java 8:


String value = Configuration.of().get("a.b.c").orElse(MyClass::calculateDefault);


Java 7:


String value = ConfigurationManager.getConfiguration().getOrDefault("a.b.c", null);
if(value==null){
 value = calculateDefault();
}


So obviously the strength of Java 8 are far beyond Streams and Lambdas:
  • The API footprint for clients overall is half the size.
  • The implementations of APIs/SPIs is much more easier and does not introduce implementation dependencies on abstract classes
  • Users must known much less artefacts to use the API!
  • It is much more flexible and extendable (eg method references)
  • ...

The above case with the deferred calculation is additionally a simple but common use case for Lambda usage. Considering implementation use cases like filtering and mapping/combining of configuration to other things Streams are incredibly useful as well. Similarly we would loose for sure great support from some of the most communities like SouJava and LJC.

So I hope I have now convinced really everybody that it is NOT worth to stick on Java 7, just because we would have faster adoption ;-) ! Do the API right for Java 8 and if enough people ask for do a backport. With the current relative small size of Tamaya a backport should be doable in about 3-4 hours ;)

105 comments:

  1. Nice comparison! But I really don't know when my customers will be ready for Java 8. Maybe in a year or two. Currently working for a customer still on Java 6!

    ReplyDelete
    Replies
    1. Apache Tamaya will also require some time to be really final in version 1.0. 6 month would be quite fast, I assume...

      Delete
  2. Are you sure that you can use "default" in Java 7 interfaces:

    >>> With Java 7 this would be (to provide similar comfort, but on the cost of implementation dependencies and limited flexibility because of missing behavioural inheritance):

    ...

    default boolean hasSameProperties(PropertyProvider provider) {...}
    default Set keySet(){...}
    default ConfigChangeSet load(){...}
    default boolean isMutable(){...}
    default void apply(ConfigChangeSet change){...}
    }

    ReplyDelete
  3. Java language was discovered by James Gosling of Sun Micro systems in 1991. Although C, C++ like programming languages were present in the market but due to fix platform constraint, web developers were unable to develop high end applications.Java

    ReplyDelete
  4. Both the source code and annotated specification information exist side by side leading to a simplified development model for
    Java developers(Java Developer "www.dev2one.com"). This information access simplicity is critical to outsource Java development
    where Java developers need to be on the same page.
    java

    ReplyDelete
  5. Is there a mailing list for Apache Tamaya? The webpage just says ". Basically it is enough to just drop as a mail on our [developer mailing list][1].", without a hyperlink. :(

    ReplyDelete
  6. Hi Admin, I went through your article and it’s totally awesome. You can consider including RSS feed for easy content sharing, So that you can drive huge traffic to your blog. Hadoop Training in Chennai | Big Data Training in Chennai

    ReplyDelete
  7. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

    Online Java Training Java Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai

    ReplyDelete
  8. I have read your blog its very attractive and impressive. I like it your blog.

    Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Java 8 online training

    Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes

    ReplyDelete
  9. I have read your blog its very attractive and impressive. I like it your blog.

    Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Java 8 online training

    Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes

    ReplyDelete
  10. I cant wait to check out some of these blogs! I’ve really wanted to start learning more about cars and auto repairs lately and I think this will help a lot. I think it can save my family some money if we knew how to do some repairs at home.! Thanks again for all the options.

    bike spa services in mumbai
    house cleaning services in mumbai
    car wash services in mumbai

    ReplyDelete
  11. Thank you for sharing such a nice and interesting blog with us. i have seen that all will say the same thing repeatedly. But in your blog, I had a chance to get some useful and unique information. I would like to suggest your blog in my dude circle. please keep on updates. hope it might be much useful for us. keep on updating.
    Sharepoint Training in Chennai

    ReplyDelete
  12. Such a great articles in my carrier, It's wonderful commands like easiest understand words of knowledge in information's.

    Salesforce Training in Chennai

    ReplyDelete
  13. I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.I'm very happy for this blog site my comment post.
    java training in chennai

    ReplyDelete
  14. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharng this information,this is useful to me...
    Android training in chennai

    ReplyDelete


  15. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharng this information,this is useful to me...
    Ios training in chennai

    ReplyDelete
  16. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  17. That was a great message in my carrier, and It's wonderful commands like mind relaxes with understand words of knowledge by information's.
    Weblogic Training in Chennai

    ReplyDelete
  18. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.
    Java Training in Chennai

    ReplyDelete
  19. Really Good blog post.provided a helpful difference between java7 and java 8 API .keep updating...
    Digital marketing company in Chennai

    ReplyDelete
  20. Thanks for your post! Through your pen I found the problem up interesting! I believe there are many other people who are interested in them just like me! Thanks your shared!...
    happy wheels

    ReplyDelete
  21. This comment has been removed by the author.

    ReplyDelete
  22. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts. java training in chennai

    ReplyDelete
  23. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic.


    Pawn Shop

    Pawn Loans

    Pawn Shops

    Pawn Loan

    Pawn Shop near me

    ReplyDelete
  24. Informative article, thanks for sharing your views and knowledge for us... it is very glad to read your article about java...

    Java courses in chennai

    ReplyDelete
  25. The Spring Framework is a lightweight framework for developing Java enterprise applications. It provides high performing, easily testable and reusable code. Spring handles the infrastructure as the underlying framework so that you can focus on your application.Spring is modular in design, thereby making creation, handling and linking of individual components so much easier. Spring implements Model View Container(MVC) design pattern.
    spring custom validator example

    ReplyDelete
  26. The Spring Framework is a lightweight framework for developing Java enterprise applications. It provides high performing, easily testable and reusable code. Spring handles the infrastructure as the underlying framework so that you can focus on your application.Spring is modular in design, thereby making creation, handling and linking of individual components so much easier. Spring implements Model View Container(MVC) design pattern.
    spring mvc validation example

    ReplyDelete
  27. It's Really A Great Post. Looking For Some More Stuff
    I really enjoyed reading the Post. It was very informative and useful for me.
    Best Java Training institute in Bangalore

    ReplyDelete
  28. Thank you for posting, its a nice post and very informative, looking for some more stuff.
    Best IT Training in Bangalore

    ReplyDelete
  29. Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing..
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  30. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
    mean-stack-training-institute-in-chennai

    ReplyDelete
  31. I am really happy with your blog because your article is very unique and powerful for new reader.
    Best Python training Institute in chennai

    ReplyDelete
  32. AWS Training in Bangalore - Live Online & Classroom
    myTectra Amazon Web Services (AWS) certification training helps you to gain real time hands on experience on AWS. myTectra offers AWS training in Bangalore using classroom and AWS Online Training globally. AWS Training at myTectra delivered by the experienced professional who has atleast 4 years of relavent AWS experince and overall 8-15 years of IT experience. myTectra Offers AWS Training since 2013 and retained the positions of Top AWS Training Company in Bangalore and India.

    IOT Training in Bangalore - Live Online & Classroom
    IOT Training course observes iot as the platform for networking of different devices on the internet and their inter related communication. Reading data through the sensors and processing it with applications sitting in the cloud and thereafter passing the processed data to generate different kind of output is the motive of the complete curricula. Students are made to understand the type of input devices and communications among the devices in a wireless media.

    ReplyDelete
  33. Your new valuable key points imply much a person like me and extremely more to my office workers. With thanks from every one of us.

    Best AWS Training in Chennai | Amazon Web Services Training in Chennai

    ReplyDelete
  34. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    Data Science Training in Chennai
    Data science training in bangalore
    Data science online training
    Data science training in pune
    Data science training in kalyan nagar

    ReplyDelete
  35. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
    Devops training in Chennai
    Devops training in Bangalore
    Devops Online training
    Devops training in Pune

    ReplyDelete
  36. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 


    angularjs Training in chennai
    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    ReplyDelete

  37. Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....


    Best Tableau online training in Hyderabad


    Tableau online training in Hyderabad


    Tableau training in Hyderabad

    ReplyDelete
  38. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
    Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune | Selenium online Training

    ReplyDelete
  39. Some us know all relating to the compelling medium you present powerful steps on this blog and therefore strongly encourage contribution from other ones on this subject while our own child is truly discovering a great deal. Have fun with the remaining portion of the year.
    Python training in pune
    AWS Training in chennai
    Python course in chennai

    ReplyDelete
  40. Thanks for your informative article, Your post helped me to understand the future and career prospects & Keep on updating your blog with such awesome article.
    DevOps online Training
    Best Devops Training institute in Chennai

    ReplyDelete
  41. I have read your blog its very attractive and impressive. I like your blog core Java online training Bangalore

    ReplyDelete
  42. Great content thanks for sharing this informative blog which provided me technical information keep posting.
    python training in velachery | python training institute in chennai



    ReplyDelete
  43. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
    Data Science Training in Indira nagar | Data Science Training in Electronic city

    Python Training in Kalyan nagar | Data Science training in Indira nagar

    Data Science Training in Marathahalli | Data Science Training in BTM Layout


    ReplyDelete
  44. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    rpa interview questions and answers
    automation anywhere interview questions and answers
    blueprism interview questions and answers
    uipath interview questions and answers
    rpa training in chennai

    ReplyDelete
  45. Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday.
    safety course in chennai

    ReplyDelete
  46. Good job in presenting the correct content with the clear explanation. The content looks real with valid information. Good Work

    DevOps is currently a popular model currently organizations all over the world moving towards to it. Your post gave a clear idea about knowing the DevOps model and its importance.

    Good to learn about DevOps at this time.


    devops training in chennai | devops training in chennai with placement | devops training in chennai omr | devops training in velachery | devops training in chennai tambaram | devops institutes in chennai | devops certification in chennai | trending technologies list 2018

    ReplyDelete
  47. Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.

    Best AWS Training in Chennai | Amazon Web Services Training in Chennai

    AWS Training in Chennai | AWS Training Institute in Chennai Velachery, Tambaram, OMR


    AWS Training in Chennai |Best Amazon Web Services Training in Chennai


    AWS Interview Questions And Answers

    ReplyDelete
  48. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
    Salesforce Training in Chennai
    German Classes in Chennai
    Salesforce certification Training in Chennai
    Salesforce.com training in chennai
    German Training in Chennai
    german classes chennai

    ReplyDelete
  49. Great work. Quite a useful post, I learned some new points here.I wish you luck as you continue to follow that passion.

    Cloud Training
    Cloud Training in Chennai

    ReplyDelete
  50. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    Java training in Chennai | Java training in Tambaram

    Java training in Chennai | Java training in Velachery

    Java training in Chennai | Java training in Omr

    Oracle training in Chennai

    ReplyDelete
  51. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    rpa training in velachery| rpa training in tambaram |rpa training in sholinganallur | rpa training in annanagar| rpa training in kalyannagar

    ReplyDelete
  52. Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.
    python interview questions and answers
    python tutorials
    python course institute in electronic city

    ReplyDelete
  53. Thanks for your sharing such a useful information. this was really helpful to me.

    naradhar
    Technology

    ReplyDelete
  54. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
    Best Devops training in sholinganallur
    Devops training in velachery
    Devops training in annanagar
    Devops training in tambaram

    ReplyDelete
  55. Thanks for providing the information . The articles in your blog helped me a lot for improving the knowledge on the subject. Also check my small collection on this at Java online course blog

    ReplyDelete
  56. Thanks for your sharing such a useful information. this was really helpful to me.

    payrollmanagementservice
    Guest posting sites

    ReplyDelete
  57. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    angularjs Training in btm

    angularjs Training in electronic-city

    angularjs online Training

    angularjs Training in marathahalli

    angularjs interview questions and answers

    ReplyDelete
  58. There are so many choices out there that I’m completely confused. Any suggestions? Thanks a lot.
    nebosh course in chennai

    ReplyDelete
  59. Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.

    AWS Interview Questions And Answers
    AWS Tutorial |Learn Amazon Web Services Tutorials |AWS Tutorial For Beginners
    AWS Online Training | Online AWS Certification Course - Gangboard
    AWS Training in Toronto| Amazon Web Services Training in Toronto, Canada

    ReplyDelete
  60. Hi,
    I must appreciate you for providing such a valuable content for us. This is one amazing piece of article. Helped a lot in increasing my knowledge.
    Android Training Chennai
    Android Courses in Chennai
    Android Mobile apps Development Training in Chennai
    AWS Training in Chennai
    AWS Training
    AWS Course in Chennai

    ReplyDelete
  61. Hi , thanks for sharing your information.The insights are really helpful and informative.
    Robotics in Coimbatore
    Learn robotics online

    ReplyDelete

  62. Excellent blog, good to see someone is posting quality information.
    DevOps Online Training

    ReplyDelete
  63. Hey, Wow all the posts are very informative for the people who visit this site. Good work! We also have a Website. Please feel free to visit our site. Thank you for sharing. Well written article Thank You for Sharing with Us pmp training courses online | pmp training fee | project management training certification | project management training in chennai | project management certification online |

    ReplyDelete
  64. Thank you for this post. Thats all I are able to say. You most absolutely have built this blog website into something speciel. You clearly know what you are working on, youve insured so many corners.thanks
    python course in pune
    python course in chennai
    python Training in Bangalore

    ReplyDelete