• Post Reply Bookmark Topic Watch Topic
  • New Topic

An Example of Java 8's Functional Style Programming  RSS feed

 
Prasad Saya
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This article is an example of Java 8's functional style programming compared to pre Java 8 code. The code is run from Java 9's JShell REPL tool. There is also code of this example using a real functional programming language. Here is the link to the article...

Prasad Saya
 
Tim Cooke
Marshal
Posts: 4038
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no attribution on that blog post. Did you write it?
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's an interesting article Please explain what JShell is. Is it some sort of interpreter where you can enter a bit of code and have it interpreted directly? Does JShell help with developing and testing code.

I shall add this discussion to the “new features” fora in the hope of more people reading it.
 
Prasad Saya
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for viewing my post.

@Tim Cooke
Yes, I wrote the post.

@Campbell Ritchie
JShell is a new Java feature with Java 9, which was released recently. I only downloaded Java 9 couple of days back and started using it (for this post), and I found JShell quite easy to use and useful. I haven't explored it yet to make any comments other than what's mentioned in my post. As you had mentioned its a sort of interpreter where one can enter a bit of code (declarations, statements, and methods) and have it interpreted directly. It helps developing and testing code quickly.

I thought it would be interesting to use the JShell in my post though its not part of Java 8. The Haskell functional programming has a similar REPL (Read-Evaluate-Print Loop) tool, and its been there since the very earlier versions of Haskell language (how early, I see it sometime before year 2000). I have been learning Haskell for couple of months, since I got my Java 8 certification recently. I found the functional programming concepts interesting and kind of randomly selected Haskell to know more about a functional programming language. The Haskell's GHCi REPL tool is very useful while learning Haskell and I got this idea to use in the post.

Prasad.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. JShell looks even more interesting now.
I haven't used Haskell, but people who have speak well of it.
 
Prasad Saya
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been learning Haskell for couple of months, I somehow feel 'nice' to know about the language (just a feeling). I also am enjoying learning Haskell as I don't have particular goals about it. Its easy to grasp the language if one knows the functional-style programming of Java 8. There are quite a few features in Java which can be related to Haskell like, lambdas, streams, filter/map/reduce functions, something like interfaces, stateless functional programming, generic types, data types,  data structures (like lists, sets and maps),... But, getting used to functions, one has to persist. And moreover there is no for loop in Haskell and values cannot be reassigned to a variable.

I think knowing a real functional programming gives a deeper insight into the Java 8's functional-style features.

There are a lot of online material to learn Haskell; I started with the following and these definitely are a good starting point, for anyone who chooses.

http://learnyouahaskell.com/ -- An online tutorial (also available as a purchaseable book)
book.realworldhaskell.org/ -- An online tutorial (also available as a purchaseable book)
https://en.wikibooks.org/wiki/Haskell --  A downloadable wikibook for Haskell language
https://www.haskell.org/tutorial/ -- A gentle introduction to Haskell 98
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!