Questions tagged [java-8]

Use this tag for questions specific to Java 8 which is version 8 (internal number 1.8) of the Java platform, released on 18 March 2014. In most cases, you should also specify the java tag.

Java 8 features the most changes ever to be introduced in a new Java version.

The most important change is the support for functional paradigm through lambda expressions and method references, under Project Lambda. This is the driving new feature of Java 8.

Other features include:

  • A new Date & Time API
  • A new Stream API integrated into the Collections API
  • Project Nashorn, a JavaScript runtime which allows developers to embed JavaScript code within applications
  • A standard API for performing Base64 encoding and decoding
  • Stronger integration with JavaFX
  • Annotations on Java types

Although it was initially advertised to be launched in September 2013, the release was pushed to March 2014 due to security issues. The GA release has been available for download from Oracle's download page since 18 March 2014.

More details on how Java 8 continues to evolve can be found on the official website and on the JDK8 mailing list.

Please keep in mind that the General Availability version of Java 8 doesn't run on Windows XP.

Reference Material

##Frequently Asked Questions

23031 questions
18
votes
4 answers

Grouping by object value, counting and then setting group key by maximum object attribute

I have managed to write a solution using Java 8 Streams API that first groups a list of object Route by its value and then counts the number of objects in each group. It returns a mapping Route -> Long. Here is the code: Map
Jernej Jerin
  • 3,179
  • 9
  • 37
  • 53
18
votes
3 answers

Some scene not loading after maven build

I am developing JavaFx application in netbeans, in netbeans the project is building and running fine. I made a build (mvn package) from my project its finished without error but when I launch the program its not loading all the scenes and the…
eszik.k
  • 1,729
  • 4
  • 17
  • 40
18
votes
2 answers

Java 8 stream - sum of objects

Let's say I have a list of objects implementing below interface: public interface Summable { T add(T o1); } Let's say I have also some class which is able to sum these objects: public class Calculator> { public T…
Piotr Kozlowski
  • 899
  • 1
  • 13
  • 25
18
votes
4 answers

Java 8 Date and Time API - parse yyyy-MM-dd'T'HH:mm:ss.SSSZ

I'm trying to parse date in ISO8601 format: yyyy-MM-dd'T'HH:mm:ss.SSSZ Am I correct that it is not possible to parse it with any of the default formats defined in java.time.format.DateTimeFormatter? For example ISO_OFFSET_DATE_TIME will parse…
vehovmar
  • 1,557
  • 1
  • 14
  • 24
18
votes
2 answers

Is there a standard way to convert a java.util.function,Consumer into a java.util.function.Function

I have a Consumer that I'd like to convert into a Function. I could achieve that by using public Function consumerToFunction(Consumer consumer) { return x -> { consumer.accept(x); return null; …
GuiSim
  • 7,361
  • 6
  • 40
  • 50
18
votes
4 answers

java 8 lambda expression for FilenameFilter

I am going through the lambda expression in java 8 when i changed the code of thread it's working fine new Thread(new Runnable() { @Override public void run() { System.out.println("run"); } }).start(); is converted to lambda…
SarthAk
  • 1,628
  • 3
  • 19
  • 24
18
votes
1 answer

Scala Futures and java 8 CompletableFuture

The introduction of CompletableFutures in Java 8 brought to the language features available in the scala.concurrent.Future such as monadic transformations. What are the differences, and why a Scala developer should prefer Scala Futures over java 8…
Edmondo
  • 19,559
  • 13
  • 62
  • 115
18
votes
2 answers

Best practice for JPA with Java8's Optional return?

I love Java8's semantics. I use a lot of such code in my DAOs : public Optional findBy(String username) { try { return Optional.of( emp.get().createQuery("select u from User u where u.username = :username" , User.class) …
smallufo
  • 11,516
  • 20
  • 73
  • 111
18
votes
1 answer

How to convert java.util.Date to Java8 java.time.YearMonth

How can I best convert a java.util.Date to a Java 8 java.time.YearMonth? Unfortunately the following throws a DateTimeException: YearMonth yearMonth = YearMonth.from(date.toInstant()); results in: java.time.DateTimeException: Unable to obtain…
Sebastian
  • 877
  • 1
  • 9
  • 20
18
votes
1 answer

Why can't I use from the static method of the implemented interface?

As you, specialists, know in Java 8, interfaces can have static methods which have implementations inside themselves. As I have read in a related tutorial, the classes which implement such interface can use its static methods. But, I have a problem…
hossayni
  • 465
  • 1
  • 3
  • 16
18
votes
2 answers

Null check in Java 8 Elvis operator?

Question: Is there an implementation of the Elvis operator scheduled for any future Java release? Or is there any Library that brings it to Java? I have read that it was proposed for Java SE 7 but didn't make it into that…
user73362
  • 353
  • 3
  • 8
18
votes
2 answers

Getting Duration using the new dateTime API

I want to get a java.time.Duration instance representing the duration of 3 years, and i found 2 ways to do it (see code below). public static void main(String[] args) { Duration d1 = Duration.of(3, ChronoUnit.YEARS); //Runtime Exception …
g7k
  • 359
  • 2
  • 15
18
votes
3 answers

What's the simplest way to convert a String Array to an int Array using Java 8?

I'm currently learning how to use Java and my friend told me that this block of code can be simplified when using Java 8. He pointed out that the parseIntArray could be simplified. How would you do this in Java 8? public class Solution { public…
18
votes
4 answers

Parsing and Translating Java 8 lambda expressions

In C# you can enclose a lambda expression in an expression tree object and then possibly parse it. I was wondering if this is also possible in Java? What I'm looking for is doing something like this: BooksRepository.getAll() .where(b -> b.getIban()…
Eyad
  • 327
  • 3
  • 10
18
votes
1 answer

Spring can't determine generic types when lambda expression is used instead of anonymous inner class

I'm playing around with Spring's ConversionService, adding a simple converter to convert a ZonedDateTime (Java 8) to String: @Bean public ConversionServiceFactoryBean conversionServiceFactoryBean() { ConversionServiceFactoryBean…
Jesper
  • 202,709
  • 46
  • 318
  • 350