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
17
votes
2 answers

ArrayList using addAll() compiler shows different behavior with generics

Can someone explain the following behavior to me? I have a list of X and use the addAll() method to add elements. These elements are returned by a method using generic types. Method getA() returns < T extends A > with A being a class. Method getI()…
firecat
  • 171
  • 3
17
votes
4 answers

Java 8 autoboxing + generics: different behaviour with variable vs. method

I found a piece of code that after switching from Java 7 to Java 8 stopped compiling. It does not feature any of the new Java 8 stuff like lambda or streams. I narrowed the problematic code down to the following situation: GenericData g =…
Quota
  • 573
  • 3
  • 11
17
votes
3 answers

Finding a Java lambda from its mangled name in a heap dump

I'm hunting a memory leak, and the heap dump shows me a number of lambda instances are holding the offending objects. The name of the lambda is the surrounding class name with $$lambda$107 at the end. I can also see that it has a single field (it…
ExMathGuy
  • 208
  • 2
  • 8
17
votes
10 answers

Java 8 - filter empty string from List not working

I would like to remove an empty String from the List of Strings. Here is what I tried, using the stream API: list.stream().filter(item-> item.isEmpty()).collect(Collectors.toList()); After that empty string is still present in the list. What am I…
Alexander Nikolov
  • 1,871
  • 7
  • 27
  • 49
17
votes
1 answer

comparing and thenComparing gives compile error

I am trying to sort List of employees by name then age using Java8 Comparator, I have created below Comparator but it gives me a compiler error Type mismatch: cannot convert from Comparator to Comparator c =…
Saravana
  • 12,647
  • 2
  • 39
  • 57
17
votes
3 answers

Get value from CompletionStage in java

I am using play2.5 with java 8. I am making POST request to server using WSRequest request = ws.url("http://abababa .com"); WSRequest complexRequest = request.setHeader("X-API-Key", "xxxxxx") .setHeader("Content-Type",…
raju
  • 4,788
  • 15
  • 64
  • 119
17
votes
1 answer

java 8 Instant.now() is showing wrong instant time

In Java 8 Instant.now() method showing wrong time . My code looks like : import java.time.*; import java.time.temporal.*; public class DateTimeDemo{ public static void main(String []args){ Instant now = Instant.now(); …
optional
  • 3,260
  • 5
  • 26
  • 47
17
votes
2 answers

Lower-bounded wild card causes trouble in javac, but not Eclipse

This piece of code compiles in Eclipse but not in javac: import java.util.function.Consumer; public class Test { public static final void m1(Consumer c) { m2(c); } private static final void m2(Consumer c) { …
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
17
votes
3 answers

What is the Maximum value for Java Duration

I tried to create a max Duration in Java 8 by using Duration.ofMillis(Long.MAX_VALUE) but got a long overflow. How would I programmatically get the equivalent of a Duration.MAX_VALUE if it existed? Edit: The long overflow was likely caused by an…
Novaterata
  • 4,356
  • 3
  • 29
  • 51
17
votes
3 answers

What is the difference between using a Predicate or a function as a Java stream filter?

So assuming I use some random filter on a stream, the most straightforward way is to directly input the Predicate: x.stream().filter(e -> e % 2 == 0) As well I can simply make a reference and define the Predicate in advance: Predicate
AdHominem
  • 1,204
  • 3
  • 13
  • 32
17
votes
2 answers

What's the difference between Stream.map(...) and Collectors.mapping(...)?

I've noticed many functionalities exposed in Stream are apparently duplicated in Collectors, such as Stream.map(Foo::bar) versus Collectors.mapping(Foo::bar, ...), or Stream.count() versus Collectors.counting(). What's the difference between these…
nasamuffin
  • 458
  • 3
  • 10
17
votes
2 answers

How does Stream.max() handle equality?

Although I suspect the answer to be "It's not specified"... If there are multiple "greatest/lowest" elements in a Stream which the Comparator passed to the max or min methods considers equal (returns 0), is it specified somewhere which element will…
Hulk
  • 6,399
  • 1
  • 30
  • 52
17
votes
3 answers

Best way to install java 8 using docker?

I have a dockerfile that starts with the following line FROM java:8 I thought this is supposed to pull the image from the docker container registry and install. no? when I run the java command inside my container I get the following error ERROR:…
user1870400
  • 6,028
  • 13
  • 54
  • 115
17
votes
3 answers

java8: method reference from another method reference

I want to use a method reference based off another method reference. It's kind of hard to explain, so I'll give you an example: Person.java public class Person{ Person sibling; int age; public Person(int age){ this.age = age; …
ewok
  • 20,148
  • 51
  • 149
  • 254
17
votes
1 answer

Java 8 repeatable custom annotations

I know about basic annotations in Java like @Override etc. Annotations are only metadata and they do not contain any business logic. I am going through repeating annotations from Oracle documentation page to understand Java 8 new feature. For…
Ravindra babu
  • 37,698
  • 11
  • 250
  • 211