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
1 answer

Limit function in Kotlin

There is a stream method limit in Java 8: package com.concretepage.util.stream; import java.util.Arrays; import java.util.List; public class LimitDemo { public static void main(String[] args) { List list =…
Letfar
  • 3,253
  • 6
  • 25
  • 35
17
votes
4 answers

issue with java 8 collectors Type mismatch: cannot convert from List to List
i was having working code with earlier version of java 8 which i was using to get unique values from list but since i upgraded to JDK 66 its giving me an error Type mismatch: cannot convert from List to List List instList =…
Nomad
  • 1,019
  • 4
  • 16
  • 30
17
votes
2 answers

Key indicators that a Java 8 stream will run slower than a for loop?

Java 8 streams allow code that is a lot more readable than old-fashioned for loops, in most cases. However, based on my own experience and what I've read, using a stream instead of a for loop can involve a performance hit (or occasionally an…
aro_tech
  • 1,103
  • 7
  • 20
17
votes
2 answers

Visualization of Java Stream parallelization

Often it's not very clear how exactly the parallel stream splits the input into chunks and in which order the chunks are joined. Is there any way to visualize the whole procedure for any stream source to better understand what's going on? Suppose I…
Tagir Valeev
  • 97,161
  • 19
  • 222
  • 334
17
votes
1 answer

When is a Java Class loaded?

I searched the internet for more than couple of hours and could not reach any conclusion. Recently I decided to use BouncyCastle for SSL but I wanted it to off by default, so that BouncyCastle jar may not be in the class path. private void…
Arun Thirupathi
  • 351
  • 2
  • 11
17
votes
1 answer

What is the advantage of using Supplier in Java?

Reading about the new Supplier interface I can't see any advantage of its usage. We can see bellow an example of it. class Vehicle{ public void drive(){ System.out.println("Driving vehicle ..."); } } class Car extends Vehicle{ @Override …
hbelmiro
  • 987
  • 11
  • 31
17
votes
1 answer

Java Lambda method reference not working

My original code is this: private static void onClicked(MouseEvent event) { // code to execute } // somewhere else in the program: setOnMouseClicked(event -> SomeClass.onClicked(event)); But IntelliJ says "Can be replaced with method…
Mayron
  • 2,146
  • 4
  • 25
  • 51
17
votes
1 answer

Java 8 parallel stream and ThreadLocal

I am trying to figure out how can I copy a ThreadLocal value in Java 8 parallel stream. So if we consider this: public class ThreadLocalTest { public static void main(String[] args) { ThreadContext.set("MAIN"); …
Anatoli Radulov
  • 556
  • 6
  • 12
17
votes
1 answer

Java 8 Stream multithreading

mylist.stream() .filter(m -> m.isokay() != null) .forEach(m -> m.dosomething())); For this code, is it running on multiple threads? If not, how can I do it? I want each m.dosomething() to run on seperate threads to speed this work up.
BufBills
  • 8,005
  • 12
  • 48
  • 90
17
votes
2 answers

using forEach to iterate over varArgs

Can I use forEach() or stream() on varArgs ? protected void getSomeIds (List... varArgs) { for(List lst:varArgs) { System.out.println("This works"); } //Following does not compile varArgs.forEach(); // nor …
Pavish Karnik
  • 239
  • 2
  • 3
  • 7
17
votes
3 answers

Parallel stream vs serial stream

Is it possible that a parallel stream could give a different result than a serial stream in Java 8? According to my information, a parallel stream is the same as a serial stream except divided into multiple substreams. It is a question of speed. All…
Ján Яabčan
  • 743
  • 2
  • 10
  • 20
17
votes
6 answers

Java 8: Lambda with variable arguments

I am looking for a way to invoke multiple argument methods but using a lambda construct. In the documentation it is said that lambda is only usable if it can map to a functional interface. I want to do something like: test((arg0, arg1) ->…
Martin Kersten
  • 5,127
  • 8
  • 46
  • 77
17
votes
3 answers

Java 8 interface default method doesn't seem to declare property

In my application I run into a problem that when a getter in a class is defaulted in an interface only (Java 8 feature), there is no Java Beans property as a result. I.e. for normal method invocation it works just as a standard method, but for…
user319799
17
votes
2 answers

Java Generic code

I am new to generics. You can see I am repeating some code after knowing the exact type of val, filterSmall, filterGreat. I want to write generic code for comparing val against filter values. I could write something like this private boolean…
Sagar
  • 5,315
  • 6
  • 37
  • 66
17
votes
3 answers

How to rewrite code to optionals?

In my current job we are rewriting some code to Java 8. If you have code like this: if(getApi() != null && getApi().getUser() != null && getApi().getUser().getCurrentTask() != null) { getApi().getUser().getCurrentTask().pause(); } you…
maxpovver
  • 1,580
  • 14
  • 25
1 2 3
99
100