Red Hat
May 4, 2015
by Thomas Qvarnström

JBoss EAP 6.4 introduced support for Java 8 as explained here. In this article we will look closer at how one can use Lambda expression within JBoss EAP.

Lambda expressions where introduced to add functional programming style to the Java languages. I'm not a big fan of functional programming, but there are some benefits like higher-order functions and lazy evaluation, which can make your code more modular. Functional programs are often shorter and easier to understand than their imperative counterparts. Since various studies have shown that the average programmer's productivity in terms of lines of code is more or less the same for any programming language, this translates also to higher productivity

Some examples:

//Without Lambda:
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
for(Integer n: list) {

//With Lambda:
List<Integer> list2 = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
list2.forEach(n -> System.out.println(n));
An example of using Lambda in Java EE:
 * Servlet implementation class LambdaMemberList
public class LambdaMemberList extends HttpServlet {
    private static final long serialVersionUID = 1L;
    List<String> names = Arrays.asList("Thomas","Eric","Christina","Kenny");

     * Default constructor. 
    public LambdaMemberList() {

    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter writer = new PrintWriter(response.getOutputStream());
try {
            writer.println("<h1>Team members:</h1>");
            names.forEach(n -> writer.println("<li>"+n+"</li>"));
        } finally {

These examples are very trivial and I would love feedback, suggestions or contribution of an more complete demo/example of using Lambda expression in Java EE.
Original Post