Questions tagged [java8]
Java 8 refers to the version of the Java platform released in March 2014.
73 questions
1
vote
2
answers
281
views
Choosing a strategy for representing and handling errors (or more generally status codes) in java 8
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 ...
1
vote
1
answer
2k
views
How to remove unused code from a jar file? [closed]
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
Best practice to create model objects in Java
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 ...
-1
votes
1
answer
603
views
How to handle pagination in a stateless application having multiple components involved for the data?
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 ...
2
votes
4
answers
2k
views
Is the Java Stream API intended to replace loops?
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
0
answers
60
views
how to handle external shared libraries, which we do not want to expose
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 (...
0
votes
3
answers
1k
views
Populate values in a map from a series of function calls
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 ...
3
votes
2
answers
2k
views
Are there any problems with using class variables in Java that can be accessed by any method?
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 ...
128
votes
11
answers
91k
views
Why use Optional in Java 8+ instead of traditional null pointer checks?
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....
7
votes
1
answer
4k
views
Should DTO have same structure as payload?
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 ...
0
votes
1
answer
3k
views
Usage of For-each loop vs functional operation vs Java8 streams
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 ...
6
votes
1
answer
2k
views
When should I create my own @FunctionalInterface rather than reuse the interfaces defined in java.util.function?
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 ...
4
votes
2
answers
1k
views
Java8: why two composition methods: andThen and compose?
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, ...
4
votes
2
answers
5k
views
Store conditional expression in database
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, ...
19
votes
1
answer
3k
views
Does it make sense to measure conditional coverage for Java 8 code?
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, ...
4
votes
2
answers
822
views
Java Design Philosophy
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 ...
11
votes
2
answers
32k
views
What's the complexity of Java's string split function?
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)...
6
votes
1
answer
4k
views
Java 8 time - LocalDateTime vs LocalDate and truncatedTo limitation handling
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) ...
0
votes
1
answer
1k
views
Reference variable concept (Java)
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 ...
1
vote
1
answer
1k
views
Java is not actually a pure object oriented programming language since it needs primitives Why?
here my Question it is said that "Java is not actually a pure object oriented programming language since it needs primitives" I want to know that how data types can affect to java be an pure object ...
2
votes
1
answer
149
views
Is this indexed approach to java rts game development valid and how can I improve it?
I have class GameState laid out to basically hold an Array of Players, an Array of StarSystems, and a few other fields that need to persist from save to save. Each GameObject keeps track of its own id,...
1
vote
3
answers
2k
views
Cyclic dependency in this project design
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 ...
1
vote
1
answer
1k
views
Supporting Multiple Java Versions in OSS Libraries
I am in the process of standing up my first OSS Java lib (GitHub/Maven) that an open source hardware community will be making fair/moderate use of.
I am writing this library with Java 8 and managing ...
28
votes
9
answers
35k
views
Why is using an optional preferential to null-checking the variable?
Take the two code examples:
if(optional.isPresent()) {
//do your thing
}
if(variable != null) {
//do your thing
}
As far as I can tell the most obvious difference is that the Optional ...
0
votes
1
answer
89
views
How confusing is `new SomeCollection(values...)::contains` as a Predicate? [closed]
Traditionally, a function that want to skip certain items during processing will accept a Collection or var-args argument, but in the Java 8 world I think I should switch to Predicates.
Now, since ...