Most voted "java-8" questions
Java 8 was released in March 2014 and contains new features, enhancements, and bug fixes to increase the efficiency of Java program development and execution.
Learn more…208 questions
Sort by count of
-
52
votes4
answers12597
viewsWhat are the advantages of Lambda Expressions in Java 8?
Java 8 will be released soon (March 2014) and the main Feature of this version are the Lambda expressions. One could describe, as the question says, what this feature will add in practice to…
-
28
votes2
answers3404
viewsHow do I migrate from Date and Calendar to the new Java 8 Date API?
Until Java 7, we had the classes Date and Calendar to represent dates. To convert them to Strings, the easiest way was with the use of SimpleDateFormat. Java 8 has introduced a new date API. How can…
-
23
votes3
answers6210
viewsWhat is the purpose of the symbol :: in Java?
I implemented a method that sums all the numbers in a list of the kind List<Integer> as follows: int soma = 0; for (Integer num : numeros) soma += num; return soma; However, the Netbeans IDE…
-
19
votes1
answer782
viewsCreate classes taking advantage of lambda
After reading this question made by utluiz, I could understand, even if in a more superficial way, a little of the usefulness of the expressions lambda added to JDK 8. However, in addition to the…
-
18
votes2
answers994
viewsWhy use a generic return?
I was looking at the signature of the class methods Optional and I don’t understand what that means <T> in front of the return of the method empty(): public static <T> Optional<T>…
-
16
votes1
answer1315
viewsHow does Spliterator work in Java 8?
In Java 8 (which was released in March 2014), there is a new interface called Splitter. She has a purpose similar to Iterator, but is designed to perform parallel iterations. However, even after…
-
15
votes3
answers17342
viewsHow to use more than one separation character in the split() method?
I’d like to break a String in various substrings, for this I am using the method split(). Turns out, I’m not sure which characters might be in the variable I use. Exemplifying: String words[] =…
-
13
votes2
answers6409
viewsWhat is a stream?
In both PHP and C#, languages I’ve been using in my day to day life, I’ve come across a common term: Stream. Whenever I hear the word Stream, the first thing that comes to mind is Youtube, among…
-
12
votes1
answer950
viewsJava Interface 8
Java 8 allows you to implement methods in the interface itself. So I’d like to know what an abstract class can do that an interface cannot. Source:…
-
12
votes2
answers381
viewsJava 8 "default method" versus C# "extend method"
Java 8 introduces the concept of "standard method" to allow adding new features to an interface. C# provides "extension methods" that allow "adding" methods(features) to existing types. Taking into…
-
11
votes2
answers4166
viewsWhat is the difference between the map() and flatMap() functions of Java 8?
What is the difference between the functions map() and flatMap() made available by the API stream java 8?
-
11
votes1
answer252
viewsIn a map/reduce in Java, should the accumulation operation generate a new object? Or can I use the old one?
I have an application that creates several objects on top of a stream of functions. And then I collect all these generated objects in a accumulator. For example, if I generated strings and…
-
10
votes2
answers4750
viewsWhat are functional interfaces?
What are functional interfaces in Java? This concept already existed or emerged from version 8 of Java?
-
10
votes4
answers2204
viewsHow to check if a Localdate is a weekend?
I have the following date of type LocalDate 2017-12-21 How to check if it’s a weekend? I tried to use the Calendar, but it seems to only work with Date.…
-
9
votes1
answer136
viewsArrayindexoutofboundsexception in Java 8 Parameter Reflection
I was making a code with Reflection in Java 8 when I came across a strange behavior - A ArrayIndexOutOfBoundsException unexpected. Based on this, I decided to create a minimal, complete and…
-
9
votes1
answer89
viewsCan the & (bitwise and) Java operator be used for interfaces?
Snippet source code from interface Comparator. Somebody explain to me how this is treated Comparator<T> & Serializable? public static <T, U extends Comparable<? super U>>…
-
9
votes2
answers710
viewsSelect "maximum" elements given a certain criterion in a "stream"
I have a collection of elements that I’m going through in a stream. Suppose it is to take the highest value element (integer) given a classification (string). This class is enough to exemplify my…
-
8
votes3
answers8112
viewsIs there any way to pass methods as a parameter?
In Java, I can pass methods as parameters? Example: public class Teste { public String metodoA(){ //faz alguma coisa } public void metodoB(double numero){ //faz alguma coisa } public void…
-
7
votes1
answer2555
viewsStream() and parallelStreams()
I saw that the performance using Amble and streams is much better than using repeat loops, so I try to use as much as possible. My question is when should I wear Streams or Parallelstreams? How does…
-
7
votes2
answers692
viewsWhat is the purpose of the super command when used in the parameter declaration of a method?
In Java the command super has the function of calling the superclass constructor. However, in the method declaration forEach() class ArrayList it is used in a different way than usual, see the…
-
7
votes2
answers515
viewsAre Ltenatives for complex conditions in a lambda expression?
With lambda expressions it is possible to filter elements from a collection of objects, creating a data stream according to the criterion passed in the expression for the method filter(), This…
-
7
votes1
answer586
viewsDo Java 8 streams and streams bring more benefits than concision?
The only benefits I understand in Amble and streams Java 8 is code saving and, as the case may be, better expressing the author’s intention. That’s all? Is there any example of code that uses one of…
java lambda-expressions java-8 functional-programming streamasked 7 years, 4 months ago Piovezan 15,850 -
7
votes2
answers837
viewsHow to implement a class to use Preparedstatement through it?
I have the following class Connect.java package util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import…
-
7
votes1
answer8513
viewsHow to do Localdatetime(Datetimezone.forID("America/Sao_paulo")) in Java.time
I wonder if there’s any way to mimic that code on java.time: LocalDateTime(DateTimeZone.forID("America/Sao_Paulo")) I don’t work very well with date in Java, if you can also explain to me what this…
-
7
votes1
answer282
viewsHashmap sorting by value and assigning to a dto using java 8
I currently have the following scenario functional: A list of the Studios class with id and name: List<Studios> studios; I count the names repeated on List thus: Map<String, Integer>…
-
6
votes1
answer361
viewsHow to Run Javascript in Java 8’s Nashorn Engine Programmatically
From Java 8 we have a new engine for Javascript execution, this is Nashorn. Which Java SE platform classes are involved in engine discovery and script execution? How to run Javascript through the…
-
6
votes1
answer441
viewsWhat is the difference between Kotlin data class and Scala case class?
In Scala we have case classes, for example: case class Pessoa(nome: String, sobrenome: String) and in Kotlin we have data classes: data class Pessoa( val nome: String, val sobrenome: String ) What’s…
-
6
votes2
answers159
viewsBetter applicability to make an interface functional
Starting from java 8, for an interface to become functional, it needs to have only one right method ? However we have the @Functionface annotation, which explicitly defines that this interface is…
-
6
votes3
answers5107
viewsWorking days and Java 8 API, how to check?
How do I verify that a day is useful using the Java 8 API? It is possible to check whether it is Saturday or Sunday, but how to check for example holiday like September 7 (Independence of Brazil) or…
-
6
votes1
answer822
viewsWhat is the difference between the orelse() and orElseGet() methods of java.util.Optional?
What is the difference between the methods orElse() and orElseGet(), class java.util.Optional?…
-
5
votes1
answer211
viewsWhat justifications/implications for the removal of Permanent Generation?
I could observe that in "Java Hotspot Performance Engine" 8 Permgen has been removed, but what was the motivation for this and where was it relocated? Is there any implication in this, for example,…
-
5
votes0
answers833
viewsError deploying to Wildfly 8: Failed to define class
I am getting the error below when trying to deploy my application, after migrating from Jboss AS 7.1 to Wildfly 8.2 and Java 7 to Java 8 and still cannot identify the source of this error. I’m using…
-
5
votes1
answer201
viewsError when deploying lambda EJB project using glassfish 4
I have in my project two java files First.java. package br.com.bom; import javax.ejb.Stateless; @Stateless public class Primeiro { } Second java. package br.com.bom; import javax.ejb.Stateless;…
-
5
votes2
answers1382
viewsRetrieve the first elements of an Integer list
I have a list ArrayList<Integer> list = new ArrayList<Integer>(); where I have over 40,000 records. I wonder if there’s a way to get only the first 10,000. I know you can make one for…
-
5
votes2
answers1863
viewsWhat is the purpose of the default when used in the signature of a method?
Within the interface List<E> of Java there is the method replaceAll() the purpose of which is to replace all occurrences of a specified value of a list. However, in his signature he uses the…
-
5
votes2
answers396
viewsHow to play relationship in Objects?
According to the definition of this website: CARDINALITY Is the maximum and minimum number of occurrences of an entity that are associated with the occurrences of another participating entity…
-
5
votes1
answer109
viewsHave the functional features of Java 8 made any Pattern design obsolete?
It is said that functional programming makes certain design patterns (thinking of the Gof) unnecessary. There’s even a presentation showing it somewhere (I’m not looking now because I’m on cell…
-
5
votes2
answers133
viewsHow to filter a Hashmap by returning another Hashmap using Java 8 lambda?
The following code traverses a Set and filters only the objects that the isActive() is true. public Set<InvoiceLineDocument> getActiveLines() { Set<InvoiceLineDocument> activeLines = new…
-
5
votes1
answer127
viewsCode Review: Simple MVC
Hello world! I tried to make a very simple MVC in Javafx. My template is a class Pessoa who owns nome and idade (the field idade in case it is not used). Two text Fields represent two views. For…
-
5
votes2
answers4293
viewsBreak and Continue on foreach Java 8
How to give a break or a continue in an iteration using forEach, in the example below, I could use the same forEach for the execution of the validation? List<Contratos> contratos= /* populando…
-
5
votes2
answers180
viewsIncorrect value in vector when binary search
import java.util.Arrays; /** * @author Vinicius * */ public class Vetor04 { /** * @param args */ public static void main(String[] args) { int vet[] = {3, 7, 6, 1, 9, 4, 5}; int s =…
-
5
votes1
answer861
viewsHow to run DOS command in JAVA with Administrator privilege?
Hello, I have a program where I need to every run of it, go on the server, pick date and time, and change on the local PC. I am running the following command line: Runtime.getRuntime().exec('DATE…
-
5
votes1
answer85
viewsWhat is the Java equivalent of this Ruby lambda?
In his text on Inversion of Control, Fowler uses as an example an excerpt of code in Ruby that promotes the said principle to "invoke a bind method over the text input field that passes an event…
-
5
votes1
answer64
viewsHow to know if the list contains so many elements that meet and do not meet a condition, using stream?
I have a list of columns, I need to know if this list contains both columns that are keys and columns that are not keys. I guarantee the existence of at least one column on the list My class of…
-
5
votes2
answers1055
viewsIf, Elseif and Else with Java 8
I would like to build a method using Java 8, replacing the conditional IF, ELSE-IF and ELSE. For this, I built a sequence of code, I do not know if it is ideal and would like to hear better opinions…
-
4
votes1
answer188
viewsHow to Distribute RIA with JNLP and Java 8
I developed an application and at the time of distributing with JNLP, I found an impasse. With Java 8, it asks to sign the Jars and the certificate must be from a recognized CA. I signed the Jars…
-
4
votes1
answer986
viewsStream -> findFirst vs findAny
The class Stream has two very similar methods, findFirstand findAny. Both return a Optional<T> with an item (or emptycase to Stream be empty). The findFirst returns the first item found. In…
java-8asked 9 years, 6 months ago Anthony Accioly 20,516 -
4
votes2
answers110
viewsHow to do for every time you pass "true", it print the entire instantiated object?
import java.util.ArrayList; public class Loja { private ArrayList<Produto> ListaDeProdutos = new ArrayList<>(); public void cadastrarProduto(Produto produto){…
-
4
votes1
answer75
viewsCompilation error on non-static element reference
public abstract class Teste { public static final Teste IMPLEMENTACAO_1 = new Teste() { @Override public void executar() { teste1(); } }; public static final Teste IMPLEMENTACAO_2 = new Teste() {…
-
4
votes0
answers48
viewsIdentify new, removed and modified objects from two ordered "collections" using extra O(1) memory in O(N) time
I have 2 "sets" of elements, neo and old, which has elements of the type T, all non-zero. Also, I know that these elements are identified by a key K and I can extract using this key using a…