Results 1 to 4 of 4
  1. #1
    radekkc is offline Member
    Join Date
    Mar 2017
    Posts
    8
    Rep Power
    0

    Default Java 8 article - functional programming, lambda expressions, stream

    I've published the first article in a series that's going to deal with Java 8 concepts such as FP, lambda expressions, streams and the Optional object:

    https://raimme.com/devcenter?article...00000m&ft=blog

    The rest of the series will deal with each of these concepts in depth, the first article is an introduction for people who got stuck with Java 7.

    I would appreciate any feedback about the article, its content and style. Thanks in advance!

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Java 8 article - functional programming, lambda expressions, stream

    A pretty good start but I think you should focus on the basics first and save streams for later. For example, you covered a method reference (e.g. System.out::println) which also happens to be a bound reference without explaining it (also vs unbound references). I recommend you provide simple examples first.

    Java Code:
    public class Demo {
    
       @FunctionalInterface
       interface Op {
           public int perform(int a, int b);
       }
       
       public static void main(String[] args) {
          
        Op add = (x,y)->x + y;
        int sum = add.perform(10, 20);
        System.out.println(sum);
        
        // or using a bound instance method reference
        
        Demo d = new Demo();
        
        Op doit = d::add;
        sum = doit.perform(20,80);
        System.out.println(sum);
          
       }
       
       public int add(int x, int y) {
          System.out.println("calling the add method");
          return x + y;
       }
    
    }

    You also didn't reference the term Functional Interface. That is key for lambdas as there can only be a single abstract method in the interface which is to be the target of a lambda expression. And finally after covering these with your own examples, you might want to direct the reader to the java.util.function package where the Java API supplies some basic functional interfaces. A few examples of those that duplicate what I gave might also be useful.

    Good luck with this!

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    radekkc is offline Member
    Join Date
    Mar 2017
    Posts
    8
    Rep Power
    0

    Default Re: Java 8 article - functional programming, lambda expressions, stream

    Hi Jim,

    Thank you for your valuable remarks. I agree putting the bound reference in the example may have been too much. As for streams, their are a big subject, but I wanted to give a simple example of not just lambdas, but also other Java 8 concepts.

    There's a lot of theory behind it, and mentioning functional interfaces is one of the key things. But as said, I thought I'd just start with an example and a layman's explanation of it, and in the second part of the tutorial I'll give the reader more theory.

    Thanks again for your suggestions!

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Java 8 article - functional programming, lambda expressions, stream

    Quote Originally Posted by radekkc View Post
    and in the second part of the tutorial I'll give the reader more theory.
    There is so much going on with this that, if you think about it, considering lambdas, method references, and streams, you could have quite a few parts to the tutorial.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Pondering about Lambda expressions
    By Iskildur in forum New To Java
    Replies: 3
    Last Post: 10-13-2016, 09:35 AM
  2. Help with lambda expressions
    By Sam_JavaTheHut5580 in forum New To Java
    Replies: 9
    Last Post: 09-08-2016, 08:42 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •