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
1271
votes
34 answers

How to install Java 8 on Mac

Editors note: This question was asked in 2014, and the answers may be outdated. I want to do some programming with the latest JavaFX, which requires Java 8. I'm using IntelliJ 13 CE and Mac OS X 9 Mavericks. I ran Oracle's Java 8 installer, and…
user3763100
  • 13,037
  • 3
  • 13
  • 9
1129
votes
17 answers

:: (double colon) operator in Java 8

I was exploring the Java 8 source and found this particular part of code very surprising: // Defined in IntPipeline.java @Override public final OptionalInt reduce(IntBinaryOperator op) { return…
Narendra Pathai
  • 41,187
  • 18
  • 82
  • 120
1049
votes
10 answers

How to convert a Java 8 Stream to an Array?

What is the easiest/shortest way to convert a Java 8 Stream into an array?
user972946
1042
votes
23 answers

Java 8 List into Map

I want to translate a List of objects into a Map using Java 8's streams and lambdas. This is how I would write it in Java 7 and below. private Map nameMap(List choices) { final Map hashMap = new…
Tom
  • 15,798
  • 4
  • 37
  • 48
963
votes
25 answers

Error:java: javacTask: source release 8 requires target release 1.8

Using IntelliJ IDE can't compile any projects. Screenshots of settings below: Used JDK: Project SDK and Language level: Language Level: Anybody have any ideas?
Hobbyist
  • 15,888
  • 9
  • 46
  • 98
961
votes
22 answers

What's the difference between map() and flatMap() methods in Java 8?

In Java 8, what's the difference between Stream.map() and Stream.flatMap() methods?
cassiomolin
  • 124,154
  • 35
  • 280
  • 359
825
votes
12 answers

How can I turn a List of Lists into a List in Java 8?

If I have a List>, how can I turn that into a List that contains all the objects in the same iteration order by using the features of Java 8?
Sarah Szabo
  • 10,345
  • 9
  • 37
  • 60
788
votes
1 answer

Why does array[idx++]+="a" increase idx once in Java 8 but twice in Java 9 and 10?

For a challenge, a fellow code golfer wrote the following code: import java.util.*; public class Main { public static void main(String[] args) { int size = 3; String[] array = new String[size]; Arrays.fill(array, ""); for (int i =…
Olivier Grégoire
  • 33,839
  • 23
  • 96
  • 137
682
votes
8 answers

Find first element by predicate

I've just started playing with Java 8 lambdas and I'm trying to implement some of the things that I'm used to in functional languages. For example, most functional languages have some kind of find function that operates on sequences, or lists that…
siki
  • 9,077
  • 3
  • 27
  • 36
656
votes
34 answers

Java 8 Distinct by property

In Java 8 how can I filter a collection using the Stream API by checking the distinctness of a property of each object? For example I have a list of Person object and I want to remove people with the same name, persons.stream().distinct(); Will use…
RichK
  • 11,318
  • 6
  • 35
  • 49
648
votes
6 answers

Should I always use a parallel stream when possible?

With Java 8 and lambdas it's easy to iterate over collections as streams, and just as easy to use a parallel stream. Two examples from the docs, the second one using parallelStream: myShapesCollection.stream() .filter(e -> e.getColor() ==…
Matsemann
  • 21,083
  • 19
  • 56
  • 89
633
votes
28 answers

Is it possible to use Java 8 for Android development?

Searching the web, it is not clear if Java 8 is supported for Android development or not. Before I download/setup Java 8, can some one point me at any "official" documentation that says Java 8 is or is not supported for Android development.
nPn
  • 16,254
  • 9
  • 35
  • 58
632
votes
26 answers

Why should Java 8's Optional not be used in arguments

I've read on many Web sites Optional should be used as a return type only, and not used in method arguments. I'm struggling to find a logical reason why. For example I have a piece of logic which has 2 optional parameters. Therefore I think it…
Neil Stevens
  • 6,745
  • 4
  • 14
  • 7
629
votes
16 answers

When to use: Java 8+ interface default method, vs. abstract method

Java 8 allows for default implementation of methods in interfaces called Default Methods. I am confused between when would I use that sort of interface default method, instead of an abstract class (with abstract method(s)). So when should interface…
Narendra Pathai
  • 41,187
  • 18
  • 82
  • 120
622
votes
28 answers

Java 8 Lambda function that throws exception?

I know how to create a reference to a method that has a String parameter and returns an int, it's: Function However, this doesn't work if the function throws an exception, say it's defined as: Integer myMethod(String s) throws…
Rocky Pulley
  • 22,531
  • 20
  • 68
  • 106
1
2 3
99 100