IBM developerWorks has a nice little article on Functional programming in the Java language: Use closures and higher order functions to write modular Java code
If you have read my blog at all, you know how I feel about closures, and this article shows some cool solutions with closure implementations.
Summary
If you work on large-scale development projects, then you’re familiar with the advantages of writing modular code. Well-structured, modular code is easier to write, debug, understand, and reuse. The problem for Java developers is that the functional programming paradigm has long been implemented only via specialized languages such as Haskell, Scheme, Erlang, and Lisp. In this article, author Abhijit Belapurkar shows you how to use functional programming constructs such as closures and higher order functions to write well-structured, modular code in the Java language
Conclusion
It has long been clear that modularity is the key to productive and successful programming on any platform. The problem for Java developers is that modular programming entails more than just decomposing a problem into parts; it also involves being able to glue small scale solutions together into an effective whole. Since this type of development is inherent to the functional programming paradigm, it seems natural to use functional programming techniques when developing modular code on the Java platform.
In this article, I’ve introduced two functional programming techniques that can be easily integrated into your Java development practices. As you’ve seen here, closures and higher order functions are not completely unfamiliar programming concepts for most Java developers, and they can be effectively combined to create a number of very handy modular solutions.
I hope this article has provided you with a good foundation for incorporating closures and higher order functions into your Java code, as well as giving you a glimpse of the beauty and effectiveness of functional programming. See Resources to learn more about the concepts and technologies discussed in this article.
July 15th, 2004 at 5:15 am
This article is also a great advertisement for new languages for the JVM as the code is really verbose.
e.g. check out this comparison…
http://docs.codehaus.org/display/GROOVY/2004/07/15/Post+on+functional+programming+in+Java+-+maybe+a+tad+verbose