Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java 8 book promotion?

 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As am new to java 8 can you provide the real time example of lambda purpose and its inclusion in java 8(play ground)
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bairava surya wrote:As am new to java 8 can you provide the real time example of lambda purpose and its inclusion in java 8(play ground)

Suppose this simple problem: print all the odd numbers in a list of integers greater than 15 without any duplicates.

In Java 7 you'll probable write something like:

The same code in Java 8:


So you'll see immediately 2 (main) advantages:
  • the Java 8 code is more concise, but it's still easy to read (maybe even better) and the compile-time safety (we all love so much) is still present as well (so the compiler knows i is an Integer)
  • with java 8 you have a well-designed library, so you can concentrate just on what needs to be done. The predicate i -> i > 15 && i % 2 == 1 is the only thing I had to write myself, all the other code is nothing more than using the library


  • And as a final note: let's assume the business requirement changes and duplicates are allowed. In the Java 7 code you have to change Set with List and HashSet with ArrayList; but in the Java 8 code you'll just remove the .distinct() line.

    Hope it helps!
    Kind regards,
    Roel
     
    bairava surya
    Ranch Hand
    Posts: 134
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thanks for simple program.whats the main usage of embedding javascript with java how it it embedded and is their any interface to do this?
     
    Roel De Nijs
    Sheriff
    Posts: 10662
    144
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    bairava surya wrote:whats the main usage of embedding javascript with java how it it embedded and is their any interface to do this?

    It's not on the OCA 7/8 exam, so we won't elaborate on this new feature in Java 8 in this forum (to avoid confusion for other aspirants preparing for the OCA 7/8 exam). Just start a new thread with your doubts/questions in the SCJP/OCPJP forum.
     
    bairava surya
    Ranch Hand
    Posts: 134
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    As what are some of the strongest concepts that made java 8 most successfull and is java8 can be used in android developing?
     
    Roel De Nijs
    Sheriff
    Posts: 10662
    144
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    bairava surya wrote:As what are some of the strongest concepts that made java 8 most successfull

    Without any doubt: lambdas.

    bairava surya wrote:and is java8 can be used in android developing?

    Currently Java 8 is not supported! You can find more info here.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic