Functional Programming in Java

This article is not supposed to be an introduction of Functional programming as it is a very vast subject. However I would like to keep it short and still give a quick intro of functional programming and how is Java doing there. Some basic features of Functional programming:

Now below are the ways in which Java encourages functional programming style though in a somewhat limited way compared to pure functional languages:

Just look at the below example of a functional programming stype in Java and how concisely we have achieved this

       Comparator<TweetMessage> tweetMessageComparatorByCreationTime = Comparator.comparing(TweetMessage::getLCreationTimeInEpoch);

        // First group the tweets by user and then sort the groups by user creation time
        Map<TweetAuthor, List<TweetMessage>> tweetListMapGroupedByAuthor =
                tweetMessageList.stream().
                        collect(Collectors.groupingBy(TweetMessage::getTweetAuthor)).
                        entrySet().
                        stream().
                        sorted(Comparator.comparing(p -> p.getKey().getLCreationTimeInEpoch())).
                        collect(toMap(Map.Entry::getKey, Map.Entry::getValue,(e1, e2) -> e2, LinkedHashMap::new));

        // Within each group, sort the messages by creation time
        tweetListMapGroupedByAuthor.values()
                .forEach(messageList -> messageList.sort(tweetMessageComparatorByCreationTime));

Just imagine writing this code in imperative style. Needless to mention that functional programming achieves very clean code.