• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why move to Java 8

 
Himanshu Ahuja
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why should a enterprise move to java 8? what are the salient feature set which would encourage update
 
Todd Placher
Greenhorn
Posts: 6
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The big ones are lambda expressions, parallel operations and javascript if you ask me.

Why would an enterprise care about lambda expressions?
Look up Anonymous function. Just about every other language did a better job of implementing it then Java like Groovy and others.
The official party line from Oracle is:
They enable you to treat functionality as a method argument, or code as data. Lambda expressions let you express instances of single-method interfaces (referred to as functional interfaces) more compactly.

To me that reads I can build code that builds code so I guess if you have a need for that in your org then it's great.

Parallel operations
Basically if you have very large/huge sorts (and with the advent of big data a lot do) then this is a good thing for you.

JavaScript
No more node.js or goofiness bridge with RPC/IPC.

There are others but that is what I took away and what I can use today at work.
 
Claude Moore
Ranch Hand
Posts: 832
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Todd Placher wrote:
To me that reads I can build code that builds code so I guess if you have a need for that in your org then it's great.


I can't imagine how... May you post an example ?
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lambda Expressions Benefits:

The code is cleaner, compact and easier to read which expand the benefits of maintainable code...

Take for example to register an action to a component you have to write the following:



Now you can write the following:



Clearly this is a benefit as there are less keystrokes to complete as well as no boilerplate code which improves on productivity and maintainability.

To carry this functionality to a domain specific problem consider that you may want a function that performs filtering on a list, but the filtering mechanism can change according to context we can create the following:







If you follow along with this example it can be seen that with the Filterable interface along with the Filter class you can filter any List on demand by just focusing on the filtering criteria without the need to type boilerplate code...
 
Claude Moore
Ranch Hand
Posts: 832
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's true, but i can't see in your example any piece of code that "builds code".. i thought that with lambda there were a mean to assign a runtime-evaluated expression and use it as function body.
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rico Felix wrote:


If you follow along with this example it can be seen that with the Filterable interface along with the Filter class you can filter any List on demand by just focusing on the filtering criteria without the need to type boilerplate code...


That's a good start, but your code is still full of boilerplate. Both of your for-each loops are boilerplate. Your temporary List is boilerplate. Even your funtional Interface is boilerplate because Java 8 provides a wide range of these for you already.* You could re-write it as follows using the Streams API:



* Java 8 provides things such as Function<T, R>, Predicate<T> and many others (for full list see the java.util.function package contents) On the one hand these probably encapsulate the vast majority of cases where a programmer would need a functional interface and so there is no need to re-create them. On the other their names are not domain specific or expressive so I may be tempted to roll my own anyway.

Note I haven't tried to compile the code above so it may well have errors.
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And thinking about it some more even my code has unnecessary boilerplate and can be simplified to:

 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. My main intention was to provide an example showing the raw functionality of a lambda expression which is to provide code as data, it was not to use the Stream API or any of the APIs hence the heading in the post...
2. Even though there are APIs at your disposal they may not contain every possible functionality that is required from the programmer, therefore the programmer either has to find a library that provides it or write it him/herself. If a programmer writes it for him/herself how does that make it boilerplate? Someone has to write it in the first place...
3. I guarantee you that there are no errors in the code so do me a favour and test it yourself...
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rico Felix wrote:1. My main intention was to provide an example showing the raw functionality of a lambda expression which is to provide code as data, it was not to use the Stream API or any of the APIs hence the heading in the post...


Fair enough, I was just giving my opinion lambdas on their own don't really make code clearer or more readable. They remove a very small amount of boilerplate code from an anonymous class definition but ultimately look almost identical. I think the real power from them comes with the style of functional programming used by the Streams API.

Rico Felix wrote:
2. Even though there are APIs at your disposal they may not contain every possible functionality that is required from the programmer, therefore the programmer either has to find a library that provides it or write it him/herself. If a programmer writes it for him/herself how does that make it boilerplate? Someone has to write it in the first place...


I'm not sure which bit specifically you're referring to there. A for-each loop is boilerplate in the same way that an anonymous class definition is boiler plate. A functional interface is boilerplate if you have to write a new one for each use even though the interfaces are the same. But then you can argue that having interface names relevant to the domain may make the code more readable.

Rico Felix wrote:
3. I guarantee you that there are no errors in the code so do me a favour and test it yourself...


Erm, I was talking about my code, not yours. Sorry if that wasn't clear.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike. J. Thompson wrote:I think the real power from them comes with the style of functional programming used by the Streams API.


This is true... I should have considered that while writing my example
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!