Feed aggregator

The Ten Most Important Lessons from JavaOne: The 20th Edition

Javalobby Syndicated Feed - Sun, 08-Nov-15 22:27

We have just had the twentieth edition of JavaOne in San Francisco. This would be my twelfth attendance in unbroken series since 2004. What are the biggest takeaways from the conferene that potentially shed a light on Java’s future?

  1. Modularization; the effort – it has taken almost nine years from the first mention of modules at Java 2007, or rather by the time that JDK 9 is released in September 2016 as general availability. In fact, it will be 11 solid years, ever since JSR 277 the Java Module System. When we think about this effort, it will be more a decade of activity and thought (See Stanley Ho’s original announcement). Oracle’s modularization of the JDK effort requires a biography of its own. Perhaps, Mark Reinhold, will get around to writing it one day, may be as the mythical man-month of the 21st century.
    It is frightening to think rewriting, effectively, Java so that it follows HIGH COHESION and LOOSE COUPLING took almost decade. Everyone else not in the JDK engineer should be extremely scared, especially if the business that you are involved in, has it own humongous mountain of TECHNICAL DEBT. Many institution cannot afford to upgrade, rewrite and reorder legacy classes, packages, let alone modules. Indeed, the cost of maintainability is about to go astronomical for those businesses that struggle under the weight and remain entrenched with Classic Java (JDK 1.0 to 7.0) For Oracle, they had no choice to pay the entire cost of development, design and architecture for the benefit of the entire Java platform and community in order to move forward to better and greater deads in the future. Oracle ought be immensely congratulated when we do reach JDK 9 GA in 2016.
  2. Modularization, the future – the new proverbial no brainer – I do believe Java and the practicing developer, designer and architect community have a LINE-IN-THE-SAND (aka DEMARCATION POINT or DISRUPTION LAYER), which we will pass through in 2016.  A modular system can change faster than the JDK platform. If Project Jigsaw is designed correctly, then you no longer have to contend with CORBA or the old fashion IBM derived java.util.Date and java.util.Calendar. In theory, you ought to be able to replace these module services and remove them if they are unnecessary. If you do not need Swing, then that module can go, same for JavaFX and AWT for server only deployment. Whilst backwards compatibility for Java platform is guaranteed, then it means opportunity for experimentation and new ideas.
    For recruitment sector, I predict, in 2017, JDK 9 will be CAMEL’S BROKEN BACK. I believe nobody will want to touch Java SE 7 or before (Classic Java) with a barge pole when they can move ahead quicker.  The top engineers will look at your job specification and run hundred miles if there is even an hint of classic Java there. You can offer £1000 per day for 6 months, but who seriously would go through technical debt and attempt to re-modularise ancient Java code, when the next women in the business down the road, is cracking on with the modern modular Java frameworks, gaining considerable experience, moving ahead of the pack, building the next greatest thing on JDK 9. On the other hand, Modularisation does not solve the technical debt, mountains or hill of it. If your business’s mission critical software is an unassailable ball of mud, then you will continue suffer the debt unless there is Agile change of behaviour. I think this is reason why the Oracle JDK 9  team want us to be the early-access early adopters in order to test their enterprise software as much as possible.
  3. More Push Java in the Cloud – At JavaOne 2015 there were a lot ideas and conference talks on Micro services and building Cloud enterprise applications.  The exhibition had a few cloud vendors like JElastic, Red Hat, Pivotal and CloudFoundry. Oracle released its own long-awaited cloud offering called the Oracle Java Cloud.  Ironically, their PaaS solution offers server clustered with Oracle Coherence, which used to be called Tangasol. Cameron Purdy, a very recent ex-Vice President of Oracle, created this early distributed grid and caching solution and, actually, one of his advocates, Brian Oliver, came to the JAVAWUG BOF 26 back in 2007 and gave a talk on Coherence.

    IMG_4162Arun Gupta for Refactor your Java EE Applications with Microservices and Containers (CON1700)

    Categories: Java

    Synchronized java.util.HashMap vs. java.util.concurrent.ConcurrentHashMap

    Javalobby Syndicated Feed - Sun, 08-Nov-15 22:07

    Using java.util.HashMap from many threads without any synchronization leads to race conditions. So we need some kind of synchronization. The easiest way is to synchronize the complete class. Another way is to use a java.util.concurrent.ConcurrentHashMap. But what does this mean to the performance of the application?
    As an example we use a HashMap to count the occurrence of a String:

    import java.math.BigInteger;
    import java.security.SecureRandom;
    import org.openjdk.jmh.annotations.Benchmark;
    import org.openjdk.jmh.annotations.Scope;
    import org.openjdk.jmh.annotations.State;
    public class MyBenchmark {
        private HashMapBasedCollectionmap = new HashMapBasedCollection();
        private String nextSessionId(SecureRandom random) {
            return new BigInteger(130, random).toString(32);
        public String[] buildNames(int size) {
            SecureRandom random = new SecureRandom();
            String[] result = new String[size];
            for (int i = 0; i < size; i++) {
                result[i] = nextSessionId(random);
            return result;
        public void testMethod() {
            String[] array = buildNames(40);
            for (int j = 0; j < 200; j++) {
                for (int i = 0; i < 40; i++) {
    import java.util.HashMap;
    import java.util.function.BiFunction;
    public class HashMapBasedCollection {
        private HashMap<String,Integer> map = new HashMap<String,Integer>();
        public static final BiFunction<String, Integer, Integer> fun
        = new BiFunction<String, Integer, Integer>()
            public Integer apply(String t, Integer u) {
                if( u == null )
                    return new Integer(0);
                return u + 1;
         * Warning: not thread safe
        public void addOne(String key)
            map.compute(key,  fun);

    As expected if we run the method “testMethod()” with two threads we see a race condition. Output from vmlens, a tool to detect race conditions:

    Categories: Java

    JSON Serialization in Scala Using SBT and Play

    Javalobby Syndicated Feed - Sun, 08-Nov-15 00:44

    Working with JSON is a very common task. In Scala, you can do it in many ways, either with the help of Java popular libraries such as Jackson or using Scala specific libraries. How do you choose from Spray JSON, Play JSON, Argonaut, Jackson, Rapture and others?

    One day I received a test task on an interview. I had to implement a JSON serialization and deserialization of a Checkout object in the context of e-commerce.

    Categories: Java

    Seeing How The Other Side Lives, A Package Manager Overview For Go Developers

    Javalobby Syndicated Feed - Sat, 07-Nov-15 05:28

    Debating and discussing Go package management has become a popular topic. Most people agree that the out of the box package management is insufficient. But, what should be used to complement the Go toolchain and what changes, if any, should the Go toolchain make?

    Package management for programming languages is nothing new. It’s worth learning and discussing how package management is handled by other languages. This can fuel our discussions and decision making. I’ve personally been studying this as part of my work on Glide.

    Categories: Java

    MicroPlode – A Microservices Experiment

    codecentric Blog - Fri, 06-Nov-15 07:43


    The Idea: What the heck does the term MicroPlode mean and what is this all about?
    The Architecture: A first sketch on a Microservice Architecture for the playground project.
    Some Technical Stuff: Well, here comes some technical stuff, yeah :-).
    Conclusion & Outlook Reflecting on the thoughts and results so far and what are the ideas for proceeding with this project.

    The Idea

    Microservices! For sure a term you can hardly dodge in the IT world these days. First time I heard about it I thought something along those lines of “nice idea, sounds really interesting”. But pretty quickly daily routine in the project took over again and washed me away from it. Then – quite recently – an idea materialised in my brain while I was reading more and more about it: Instead of only reading about it in theory, let’s do this in practice using a small – but somewhat meaningful – “playground project”. And puh, there are tons of blog posts out there to read on the topic. For example lately I was reading through this more skeptical blog post on DZone including roughly 100 comments discussion. It was really interesting as it was going from technical aspects to social aspects and back again. I really gained some insights from that. In the end this encouraged me in my idea to try the whole thing out in practice. And thanks to our company’s great working model that allows us to spend a decent amount of time exploring new technologies, I have the opportunity to start this little experiment here and now :-).

    The playground project will be a game based on an old gaming idea. Unfortunately I forgot the name of the original game, so if someone recognises the original game it would be great to leave me a comment.

    The game is played in turns with two or more players on a playing field that for the beginning is assumed to have a fixed size of 10×10 fields. When starting a new game, all fields are unoccupied. Players can occupy one empty field when it is their turn or they can increase the load on one field already owned by them.

    • If a field is empty, the field will be occupied by that player with a load of one.
    • If a field is already occupied by that player the load on that field will be increased by one.
    • Players can only access empty fields or those already occupied by them.
    • If after increasing the load a field has a load that is higher than the amount of direct neighbouring fields it explodes and gives a load to each of those neighbouring fields.
    • A field getting a load this way is changing ownership to the one of the exploded field. A load already on such a field is increased by one no matter by whom that field was owned previously.
    • A field getting a load this way might explode itself again leading to nice chain reactions.
    • If after the first round a player does not own any field on its turn that player lost the game.

    It is really fun playing and I implemented this already a long time back using Java with SWT. Unfortunately I lost all the sources. So this is a nice goal to implement and at the same time I know it is possible in a reasonable amount of time. And it is fun implementing computer players for this, but that is a later story.

    The version of this game I once implemented was called Explode, thus the name MicroPlode for this project :-).

    This is really the beginning of a journey with an open end. I have implemented nothing so far and I only have a few ideas regarding the technologies I would like to use. Furthermore it might turn out it does not make sense at all to implement this game using Microservice architecture, even though I thought a little bit about this in advance. I also discussed it a bit with a colleague who has more experiences in this area. Anyway, as with every project I am also starting optimistic into this one :-).

    The Architecture

    Architecture, yeah! I always involuntarily cringe a bit when writing the term “Architecture” in a blog post as from my personal observation this term is a bit overused these days. But talking about Microservices and how to model them seems to well deserve that term :-).

    Ok, I have read and heard that finding the borderlines between the individual services is one of the hardest parts in a Microservices Architecture. As always with examples it is easier than in real-life projects, but still this is the result of some hard thinking and discussion :-). I see three building blocks for the game that will be implemented as Microservices and communicate via messaging. Let’s sketch them shortly before we go into more details.

        GameService – Administration of games and players, keeps track of scores and knows whos move it is. It also detects if a player looses the game and if the game is over if there is only one player left in the game.
        PlayerService – Calculates moves based on the current game state for computer players. Allows human players to make a move.
        PlayingFieldService – This service knows the playing field or one could even say it is the playing field :-). It initializes the board and changes the board state depending on moves that have been made by players. It is furthermore capable of executing explosions when needed.

    Right now my brain – used to monolithic applications – is already whispering: Hey, the GameService and the PlayerService are for sure sharing some information on players. And think of the computer player, that one needs to know everything about the playing field at least as good as the PlayingFieldService. – Well, I understood that duplicating data to a certain degree is one of the tradeoffs in a Microservices Architecture, so let’s wait and see. By the way, nobody told me so far that there is the danger of becoming schizophrenic when working with Microservices :-).

    Technical aspects aside, those three Microservices need to exchange information of course. Such a game is now of course nothing that has a lot of asynchronous things to do. It is someone’s turn, a move must be calculated and the change in game state that move triggers must be tracked. Nevertheless we will use messaging for communication here. For the sake of learning things and let’s see what it might be good for in the end. Let’s take a look at the the following figure depicting the communication between the services:

    Services and Events

    As in every project, this is work-in-progress, but for the time being this is hopefully good enough to start implementation. Let’s take a look at the events and what actions they should trigger in the different services.

    And again some thoughs are coming up I would probably not have in a monolithic approach. Is there an order I need to start the services in later on? (Though I know this must not be the case.) Then do I need to acknowledge all or certain events? Probably this should be solved technically by the platform used for sending/receiving events.

    At the same time I get a positive feeling of clearly divided responsibilities. Even though all of the services need to work with the board state, they all do different things with it and thus I will be really forced (in a positive way) to split those responsibilities. Of course this will come at the cost of needing some kind of board representation in different services. A really interesting experiment :-).

    The GameService has to know which players are available. Therefore we need the registration-event. This also leads to a somewhat open issue that is spooking around in my mind, namely that we will probably not have only one PlayerService, but multiple instances for different computer players and human players. Getting more concrete on that will be done at a later point in time, though.

    Then the GameService must also know that the PlayingFieldService is ready to work using the board-ready-event.

    If a new game is started, this must be propagated to the PlayerService(s)

    Categories: Agile, Java, TDD & BDD

    Applying IDE Inspections to Custom Java Annotations

    Javalobby Syndicated Feed - Fri, 06-Nov-15 02:51

    The introduction of annotations with J2SE 5 has changed how we write and process Java. Besides Java SE's predefined annotations, frameworks, IDEs, and toolkits have introduced their own custom annotations. The Checker Framework has provided examples of how custom annotations can be used to add greater type safety in Java. In this post, I look at the writing of a simple custom annotation and using it in NetBeans (8.0.2) and IntelliJ IDEA (14.0.3) to help developers identify issues in their code that need further attention.

    In the article Making the Most of Java's Metadata, Part 2: Custom Annotations, Jason Hunter demonstrates an @Unfinished annotation as an example of writing a custom Java annotation. I will demonstrate a different implementation of an @Unfinished annotation in this post. That's the beauty of custom annotations: one can write an annotation to best fit one's needs. The code for my @Unfinished annotation is shown in the next code listing.

    Categories: Java

    Java EE App Servers: Are They Still Relevant in a World of Docker Containers?

    Javalobby Syndicated Feed - Thu, 05-Nov-15 23:44

    This year at JavaOne 2015 there was a recurring theme across many of the Cloud and DevOps tech sessions that were promoting self-contained deployable JARs (not EARs or WARs) as a more efficient approach for deploying lightweight Java based services. This approach also plays well for a microservices type architecture and can also easily make use of containers, like Docker, PaaS offerings like CloudFoundry or Heroku, or even Oracle’s new Java SE Cloud Services offering.

    Being able to deploy small, self-contained services (compared to large, monolithic EARs) brings a whole range of benefits, like being able to deploy more often, and deploy individual services individually without touching or impacting any of the other deployed services.

    Categories: Java

    Implementing Auto Retry in Java EE Applications

    Javalobby Syndicated Feed - Thu, 05-Nov-15 22:47

    Initially, I wanted to call this blog – ‘Flexible timeouts with interceptor driven retry policies‘ – but then I thought it would be too ‘heavy’. This statement, along with the revised title should (hopefully) give you an idea of what this post might talk about ;-)

    The Trigger

    This post is primarily driven by one of the comment/questions I received on one of my earlier posts which briefly discussed timeout mechanisms and how they can be used to define ‘concurrency policies’ for Stateful and Singleton EJBs.

    Categories: Java

    For Java Developers - Akka HTTP In The Cloud With Maven and Docker

    Javalobby Syndicated Feed - Thu, 05-Nov-15 22:05

    From time to time it is necessary to just take the little effort to think outside the box. This is a good habit for every developer and even if you just spend 10% of your time, with new and noteworthy technology, you will gain experience and broaden your knowledge. I wanted to look into Scala and Akka since a while. Both well known old acquaintances on many conference agendas. But honestly, I've never felt the need to take a second look. This changed quite a bit when I started to look deeper into microservices and relevant concepts around it. Let's get started and see what's in there.

    What Is Akka? And Why Scala?

    Categories: Java

    Under The Boot – Spring Boot

    Javalobby Syndicated Feed - Thu, 05-Nov-15 00:57

    Remember the times when we had to register dispatchers, viewResolvers, etc. to make our spring application web app? Then there was @EnableWebMvc annotation, and now even this is redundant.

    These days the only thing you need to do is to add org.springframework.boot:spring-boot-starter-web dependency to your project and everything else is done automagically.

    Categories: Java

    What Might a New @Deprecated Look Like?

    Javalobby Syndicated Feed - Thu, 05-Nov-15 00:51

    JDK Enhancement Proposal (JEP) 277 ("Enhanced Deprecation") proposes to "revamp the deprecation annotation and provide tools to strengthen the tail end of the feature life cycle." Some of the limitations of the current @java.lang.Deprecated have bothered me for some time. I particularly would like to be able to provide text with @Deprecated rather than being forced to place explanatory text in a corresponding Javadoc @deprecated comment. In this post, I look at a custom annotation that gives a feel for the type of extra metadata JEP 277 proposes be included in a new and improved @Deprecated annotation.

    The code listing that follows contains the definition of dustin.examples.annotations.Deprecated, an implementation which mostly mirrors what is described in the JEP 277 proposal.

    Categories: Java

    Working With Java 8 Optionals

    Javalobby Syndicated Feed - Wed, 04-Nov-15 23:48

    In this post we are going to cover working with the Optional class introduced in Java 8. The introduction of Optional was new only to Java. Guava has had a version of Optional and Scala has had the Option type for some time. Here’s a description of Optional from the Java API docs:

    A container object which may or may not contain a non-null value.

    Categories: Java

    How to Debug a Groovy Script From Shell

    Javalobby Syndicated Feed - Wed, 04-Nov-15 22:37

    Groovy is a scripting language, so it is possible to run Groovy code without compiling to Java byte code. The necessary condition is that Groovy is installed on your machine. Then, running a Groovy script in a shell looks like the following line:

    ~>groovy TestScript.groovy

    Now, something is wrong with the script on a special environment. You want to debug your Groovy script from the shell.

    Categories: Java

    Java Memory Architecture Cheat Sheet

    Javalobby Syndicated Feed - Wed, 04-Nov-15 12:39

    The diagram below is the Java Memory Model for the Heap as well as the PermGen for any Java Application running in the Java Virtual Machine (JVM). The ratios are also provided to get a fair understanding of how the distribution of allowed memory is done across each of the generation types. All of the info is completely applicable up to Java 1.7 (inclusive). This diagram is also known as the 'Managed Area' of the memory model.

    Java Memory Architecture (Java Memory Model)

    Image title

    Categories: Java

    Structure of Tests-As-Specifications

    Sustainable Test-Driven Development - Wed, 04-Nov-15 12:07
    A big part of our thesis is that TDD is not really a testing activity, but rather a specifying activity that generates tests as a very useful side effect.  For TDD to be a sustainable process, it is important to understand the various implications of this distinction. [1] Here, we will discuss the way our tests are structured when we seek to use them as Scott Bainhttp://www.blogger.com/profile/05410128716057054818noreply@blogger.com1
    Categories: TDD & BDD

    Code Challenge Series: Substring Search

    Javalobby Syndicated Feed - Tue, 03-Nov-15 23:14

    Last week we had Fizz Buzz code golf and the winner was Mark Ogden in Perl with an amazing 63 characters.

    There were a couple of answers that were also very close to that as well so well done to them too.

    This weeks challenge is a little harder and should really tax your brains. Basically I would like you to find the first instance of an arbitrary length substring within a string without using regular expressions or the find/indexOf/search functions of the String object. So writing it in a low level aproach at a character level.

    So in the case of the above example I am looking for the index of the first letter of the word end in the string you see there.

    Categories: Java

    Github Flavored Markdown + OSGi + dotCMS

    Javalobby Syndicated Feed - Tue, 03-Nov-15 22:22

    As a Java based CMS, dotCMS handles a lot of different use cases for managing and delivering content. Recently, we were asked if dotCMS can deliver Github flavored markdown content. We thought that this would be a great example of how easy it is to extend dotCMS with OSGi plugins. (As a side note, this blog - as seen on dotcms.com -  is actually written using the plugin).


    Some background for developers stuck in 2008, Markdown is a text to html parser originally written by John Gruber. It provides a user a simple, small set of markup tags that is parsed and rendered as standard HTML for consumption by browsers or even less capable views or viewports. Github Flavored Markdown, or GFM, offers a few extensions for further formatting, including support for strikethrough, url auto-linking, syntax highlighting and tables, Because of the ubiquity of github as a coding resource, GFM has become a de facto standard for commenting, documentation and other online authoring tools that needs support for formatting, but want to limit, uh, “creativity”.

    Categories: Java

    A New Java Library: ParallelGit

    Javalobby Syndicated Feed - Tue, 03-Nov-15 15:17

    Hi all. Just published an open source library to the Maven Central Repository. As the author of this project, I am here to shout out the exciting news :)

    ParallelGit is a library to help you manipulate your local Git repository. It allows you to access your repository as it were a native file system (via Java 7 nio FileSystem interface).

    Categories: Java

    JetBrains Releases IntelliJ IDEA 15

    Javalobby Syndicated Feed - Tue, 03-Nov-15 08:43

    Today, JetBrains announced a new release of their popular IDE IntelliJ IDEA. The company promised the new release brings a new set of features and tools, UI improvements, and improved coding assistance. 

    In addition, JetBrains' new in-development JVM language, Kotlin, has gone into Beta. Naturally, the new language is supported in IntelliJ IDEA 15. 

    Categories: Java

    DZone's Zone Leader Spotlight – Dave Fecak

    Javalobby Syndicated Feed - Tue, 03-Nov-15 08:42

    Background: What is a Zone Leader? 

    Recently I've taken charge on what I think is a great opportunity for writers and topic experts in the devsphere—our new Zone Leader Program. In a nutshell, the Zone Leader Program is an effort to put topic experts and practioners in the software industry at the helm of the content we publish on DZone. A sizeable portion of the content you've been reading on DZone recently has actually been written or published by Zone Leaders!

    If you're interested in learning more and maybe being a Zone Leader yourself, shoot me an email.

    Categories: Java

    Thread Slivers eBook at Amazon

    Syndicate content