Skip to main content

Questions tagged [java8]

Java 8 refers to the version of the Java platform released in March 2014.

Filter by
Sorted by
Tagged with
6 votes
1 answer
4k views

I am new to the Java 8 time package, and am trying to better understand it and make sure that I am making good use of it. Is there a specific reason that LocalDateTime's truncatedTo(TemporalUnit) ...
118 votes
3 answers
116k views

In Java 8's java.util.function package, we have: Function: Takes one argument, produces one result. Consumer: Takes one argument, produces nothing. Supplier: Takes no argument, produces one result. .....
2 votes
4 answers
2k views

I mean the question in the sense of: Should the occurrence of simple loops on collections in code in Java 8 and higher be regarded as code smell (except in justified exceptions)? When it came to Java ...
1 vote
2 answers
288 views

I asked this questions on StackOverflow but it's definitely a bit too broad. Even for this website, although the question is about software design, it might not be enough "focused". I am ...
16 votes
1 answer
3k views

I'm designing an interface with two related methods, similar to this: public interface ThingComputer { default Thing computeFirstThing() { return computeAllThings().get(0); } ...
2 votes
2 answers
5k views

I am building a wrapper for a library that requires little complex logic. The whole project is 8 builder classes, 4 classes for doing some pre-processing, and a couple visitor classes. Essentially I ...
1 vote
1 answer
2k views

I have a jar file, for example foo.jar. My code contains a lot of libraries (almost 75 jar dependencies). I am not using anything like maven or gradle, I'm just using pure java with pure jar files as ...
0 votes
1 answer
1k views

I have an existing microservice that talks to a Natural Language Processing (NLP) product and fetches around 50 fields. I need to create domain objects in Java now from these fields. I read about ...
14 votes
1 answer
2k views

I have been trying to understand why the JDK 8 Lambda Expert Group (EG) decided not to include a new function type into the Java programming language. Going over the mailing list I found a thread with ...
50 votes
4 answers
22k views

for (Canvas canvas : list) { } NetBeans suggests me to use "functional operations": list.stream().forEach((canvas) -> { }); But why is this preferred? If anything, it is harder to read and ...
-1 votes
1 answer
207 views

I have a method where I fetch user input, check if certain values exist, and based on that build my own custom input object that I would use to search in a database. The code for the search method is ...
-2 votes
1 answer
70 views

I have tried this piece of code: String[] latitudesArray = latitudes.split(","); String[] longitudesArray = longitudes.split(","); Double startLat = ...
111 votes
5 answers
96k views

In Java 8, interfaces can contain implemented methods, static methods, and the so-called "default" methods (which the implementing classes do not need to override). In my (probably naive) view, there ...
-1 votes
1 answer
603 views

This problem statement is around one UI component, 3 service components. The current design of the application is like: UI makes request to Service-A to get data Service-A first makes a call to ...
7 votes
2 answers
14k views

I am writing an API (using Java) that takes locale as a parameter. We want the clients to be able to specify "en-US" or "en_US" as they both seem to be widely used across all languages. I did go ...
-2 votes
1 answer
818 views

I have the below default method in an interface and it seems to be pretty complex because of the many if-else conditions. default void validate() { Application application = application().get(); ...
52 votes
7 answers
25k views

I appreciate a lot the new Java 8 features about lambdas and default methods interfaces. Yet, I still get bored with checked exceptions. For instance, if I just want to list all the visible fields of ...
59 votes
3 answers
44k views

Suppose I have a stream of Things and I want to "enrich" them mid stream, I can use peek() to do this, eg: streamOfThings.peek(this::thingMutator).forEach(this::someConsumer); Assume that ...
-5 votes
1 answer
144 views

About 4 years ago, where I was working, software was still being developed with Java 7 + Swing. It took me a couple years, but we could finally migrate to Java 8 + JavaFX, two years after that. Now ...
1 vote
0 answers
60 views

We have 800-900 services we expose via an ESB. Each service is a web app hosted on Tomcat servers. We have 4 tomcat servers per group of services. Our services are split into 4 groups. Each service (...
128 votes
11 answers
91k views

We have recently moved to Java 8. Now, I see applications flooded with Optional objects. Before Java 8 (Style 1) Employee employee = employeeServive.getEmployee(); if(employee!=null){ System....
1 vote
0 answers
49 views

Why is it that some abstract methods in interface hierarchies are redeclared as abstract further down? iterator() for example, abstract in Collection is redeclared in Set and List, and again further ...
0 votes
3 answers
1k views

I have the following common pattern that I need to use in an application: Given a list of keys, call a function with a parameter to find values for the keys. The function may return null for a given ...
5 votes
3 answers
3k views

link : http://download.java.net/jdk8/docs/api/java/lang/annotation/Native.html In Java 8, there will be @Native annotations. Indicates that a field defining a constant value may be referenced from ...
4 votes
4 answers
2k views

Background While writing a new component, I m in middle of making a decision of SQL/NOSQL database (Mongo vs Mysql) for my storage layer. As of today, mysql seems to be a perfect fit for my use-case (...
74 votes
3 answers
35k views

Do method references skip the overhead of the lambda wrapper? Might they in the future? According to the Java Tutorial on Method References: Sometimes... a lambda expression does nothing but call an ...
69 votes
3 answers
59k views

Java 8 has a whole new library for dates and times in the package java.time which is very welcome thing to anyone who has had to use JodaTime before or hassle with making it's own date processing ...
3 votes
2 answers
2k views

So I've been coding in Java for a decent amount of time, but recently, I've started a class that cares about my coding design. In the past, if I had two methods inside a class that needed to edit the ...
5 votes
1 answer
25k views

I'm learning concurrency in Java and went over the tutorials on Oracle website. While I have understood some of it, a greater portion eludes me. I was thinking of a hypothetical problem (though it may ...
0 votes
1 answer
189 views

I have a LogFormatter class which looks like below @Sl4j class LogFormatter { public static String format(String taskType, String taskId, String message) { return String....
0 votes
1 answer
812 views

I have various types of tasks, each task involves the following - Use an XyzAPIProvider to query and obtain a payload convert the payload into a list of XyzDTOs (ModelMapper) convert the list of DTOs ...
7 votes
1 answer
4k views

I have a usecase where I am supposed to store entire payload from a third party API in addition to the DTO, say XYZDto, its translated to. There are two ways to achieve that - Translate the payload ...
3 votes
1 answer
676 views

We are developing a REST application based on an MVC architecture. The service layer is returning Optional<T> where T could be any class. So on the controller layer there is a conditional ...
0 votes
1 answer
3k views

What are the gains in actual computing speed (verbosity of code being put aside) and for which case would each be recommended for, as a good design pattern? I would like to know the above in general ...
0 votes
1 answer
876 views

I am developing on a a large webapp system that has multiple docker containers. Imagine a webapp but with many external restful services running on different containers. A microservices setup. I ...
4 votes
2 answers
1k views

As a beginner in both java8 and functional programming, I think I'm missing something when reading about function composition since I cannot find a reason why there are two methods that do this, ...
6 votes
1 answer
2k views

The functional interfaces in java.util.function cover the vast majority of common strategies one might want to apply, but it's also possible to define your own @FunctionalInterface instead. In cases ...
6 votes
1 answer
1k views

Recently, we have started to migrate a spring application to java 8. The application is divided into 3 layers, rest controllers, service and the repository layer. Our 'architect' proposed that our ...
-2 votes
1 answer
611 views

I have been reading the source code of some Java library classes, specifically CompletableFuture. I noticed that the authors are making extensive use of cryptic (single-letter) variables in the code, ...
4 votes
2 answers
5k views

We have an application that allows users to enter conditionals in the form bound op x op bound2, we store this as a string, and then parse it at runtime to evaluate it. It is a decent amount of work, ...
13 votes
5 answers
8k views

I've just recently noticed there is an option to have static methods in interfaces. Same as with static fields of interface, there is an interesting behavior: These are not inherited. I'm unsure it's ...
19 votes
1 answer
3k views

I'm wondering whether measuring conditional code coverage by current tools for Java are not obsolete since Java 8 came up. With Java 8's Optional and Stream we can often avoid code branches/loops, ...
20 votes
1 answer
14k views

The following Scala code works and can be passed to a Java method expecting a function. Is there a cleaner way to do this? Here's my first pass: val plusOne = new java.util.function.Function[Int,...
4 votes
2 answers
826 views

I was reading through design philosophy of java and this line struck me: "The VM checks whether the signature of the Java code is valid and would refuse to interpret if any change of the code is ...
13 votes
1 answer
6k views

When I call Stream.sort(..) is there a new array of elements created and the stream iterates over the newly created sorted array? In other words, how Java 8 Stream does sort under the hood?
11 votes
2 answers
32k views

My string is of type"abacsdsdvvsg" or"a a a a a a a" And I use String[] stringArray = s.split(""); or String[] stringArray = s.split(" "); I'm wondering what would be the complexity(in O(string length)...
1 vote
3 answers
4k views

This program run successfully . What is use of blank return in constructor as we know it return this implicitly . Is it is a bug in java or have some use . class Demo { int salary; Demo() ...
1 vote
3 answers
2k views

I have 2 modules (containing multiple classes). Let's call them Module A and Module B. Module B has a dependency on Module A: Module B -> Module A. Now, I have created an utility class C, which A ...
0 votes
1 answer
1k views

I'm working my way (slowly, but surely) through a book: Introduction to Java Programming, 10th edition, Comprehensive, by J. Liang (ISBN10: 0133761312) It explains the idea of a reference variable ...
10 votes
3 answers
2k views

In the new java.time package the core classes are using the factory method of instead of a public constructor. Even though I like the cosmetics of the of method I can't see a good reason to not use a ...