Link Details

Link 949083 thumbnail
User 448255 avatar

By dotCore
Published: Apr 03 2013 / 16:27

The following examples make extensive use of the new features in Java 8 to implement the concept of a stream: a classical data structure similar to a list that uses lazy evaluation. This is not exactly how they have defined the new streams API in Java 8 (you can find other articles I have written about this at the end), but for me it worked as an excellent exercise to understand important concepts like lazy evaluation, the creation of closures through lambda expressions and the value of the new features like default methods and static methods in interfaces. The concept is based on the same idea of a stream developed in Lisp by Abelson and Gerald and Julie Sussman in their book Structure and Interpretation of Computer Programs. In this article I will develop several examples of infinite streams with Java, particularly an infinite stream of natural numbers, and on top of that, an infinite stream of prime numbers using the sieve of Eratosthenes and finally an infinite stream of Fibonacci numbers.
  • 9
  • 0
  • 1220
  • 1278

Add your comment

Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Apache Hadoop
Written by: Piotr Krewski
Featured Refcardz: Top Refcardz:
  1. Play
  2. Akka
  3. Design Patterns
  4. OO JS
  5. Cont. Delivery
  1. Play
  2. Java Performance
  3. Akka
  4. REST
  5. Java