Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java 8: What are the good features you will advise to use?  RSS feed

 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java 8 seems a big deal. What features do you think are most useful in our daily work?

I also see a chapter about Scala. What's this chapter about. It seems Java 8 borrows something from Scala, for example the Option object.
 
Raoul Gabriel
Author
Greenhorn
Posts: 20
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Qunfeng,

Java 8 is a major deal. It is the largest update to the language in 10years :-)

To answer your first question:

Why is Java 8 changing again? Because of two trends that could not be ignored:

1) The increasing need to exploit the power of multi-core processors in a programmer-friendly way
2) The increasing demand of processing collections of data with database-like operations (e.g. filter, map, grouping)

Neither of these trends is effectively supported by the traditional object-oriented imperative approach centred around mutating objects, and applying iterators. However, they are easily supported using ideas from functional programming, which Java 8 has taken inspiration from.

This new version of Java incorporate features popular in many other programming languages to respond to these two trends: the ability to represent a piece of behaviour in a concise form (called lambda expressions) and database-like operations on collections (called the new Streams API). In addition, it brings other popular ideas that will impact how you write code on a day to day: default methods (implementation code inside interfaces), the class Optional (an alternative to the null reference), the class CompletableFuture (composable asynchronous programming) and a new Date and Time API designed with immutability in mind.

To answer your second question:

Java 8's design is inspired from Scala in many ways. However, Scala provides a richer set of features around the new features introduced in Java 8. For example, anonymous functions in Scala (the equivalent of lambdas in Java 8) don't have write restrictions on local variables. Traits in Scala (the equivalent of interfaces with default methods in Java 8) can also be composed at object-instantiation time.

We believe you may find interesting to compare the approach taken by Java 8 and see its limitations. This is what this chapter aims to shed light on. It doesn't aim to teach you Scala.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!