Java Lambda expressions

Before Java 8, calculating the number of primes below 100,000 could have involved a nested iterative loop.
class Maths {
    public static void main(String[] args) {
        Instant start = Instant.now();
        int count = 0;
        outer: for (int i = 2; i <= 100000; i++) {
            for (int j = 2; j < i; j++) {
                if (i % j == 0)
                    continue outer;
            }
            count++;
        }
        System.out.printf("%d primes calculated in %d.1 seconds", count, Duration.between(start, Instant.now()).toMillis()/1000);
    }
}
Lambda expressions are blocks of code whose execution can be deferred, simplifying concurrent programming. The following example parallelises the calculation.
class Maths {
    public static void main(String[] args) {
        Instant start = Instant.now();
        long count = 
        IntStream.range(2, 100000). //generate a sequence from 2 to 100,000 
        parallel(). //returns a parallel stream, enabling concurrent execution
        filter(p->!IntStream.range(2, p).anyMatch(n -> p % n ==0)). //predicate determines if p is a prime number 
        count(); ///terminal operation reduces the stream to a value
        System.out.printf("%d primes calculated in %d.1 seconds", count, Duration.between(start, Instant.now()).toMillis()/1000);
    }
}
For an example of running this as a JavaFX application, click here