Questions tagged [java]
Java is a high-level, platform-independent, object-oriented programming language originally developed by Sun Microsystems. Java is currently owned by Oracle, which purchased Sun in 2010.
5,020 questions
1
vote
4
answers
150
views
Is it good practice to return ApiResponse from a Spring service layer?
I'm working on a Spring Boot application with a VoucherService and VoucherController. I currently have the service method return an ApiResponse<T> directly, like this:
@Transactional
public ...
7
votes
3
answers
545
views
What SOLID principles does the Java List interface challenge?
The Java List<E> interface includes methods, such as add(E) and remove(Object), that work as the names suggest on instances of mutable concrete implementations, such as ArrayList<E> and ...
1
vote
1
answer
215
views
What is the difference between Vertical Slice Architecture and Feature-Based Architecture
I am refactoring my monolithic application, in which the code is organized based on layered architecture.
I want to implement Modulith (Modular Monolit) in my app, but I've run into a problem: I haven'...
0
votes
2
answers
142
views
A class that implements two interfaces that extend the same interface [duplicate]
I'll get straight to the point. I want to implement a class structure in Java similar to the one in the image.
Am I falling into bad practice with this kind of diamond-shaped interface implementation?...
2
votes
3
answers
636
views
Convenience inheritance
Sometimes, you inherit from a class that defines the semantics of your type (Shape – Ellipse – Circle). Other times, you inherit simply because it's convenient to do so.
A superclass may have ...
1
vote
2
answers
256
views
Testing GUI panel involving modal dialogs
Suppose you have a panel with a table, which I will call a pane.
The table has a toolbar above it, including an edit button.
Editing involves showing an editing dialog. It allows the user to edit the ...
0
votes
2
answers
203
views
Keeping the impact of changes low when moving shared domain objects into a library
I’m refactoring a microservice project where multiple services share the same domain objects. Over time, these objects have diverged across services, causing inconsistencies.
To solve this, I plan to ...
4
votes
2
answers
327
views
Managing Growth in Microservice Architecture: Is Modular Monolith the Solution?
Our team of 5 members are managing a microservice architecture that currently includes around 200 Java Spring boot microservices, with approximately 50 new services being added each year. We follow ...
0
votes
3
answers
217
views
Tracking data change in GUI form
Problem: our application allows users to close a form window after certain changes without any confirmation, instead of pressing the Save button. This makes them complain they have to start afresh.
We ...
1
vote
2
answers
207
views
Classpath hell: independently updated apps with shared dependencies
This is how our desktop applications are launched. In this case, it's called DesktopApp (I changed the actual name). As you see, the dependencies are hard-coded, including their versions. In the ...
0
votes
1
answer
131
views
How to create a job management for a hybrid cloud/on-premise software?
I am exploring the state-of-the-art methods to create a service that can run and scale in both cloud (container) and on-premise environments.
The current version of the software is designed for on-...
0
votes
1
answer
114
views
Designing a Scalable Caching Layer for User and Tenant Metadata in a Messaging System
I'm developing a microservice-based application that processes a high volume of messages. Each message must be handled according to the user’s personal settings and some tenant-specific (customer) ...
2
votes
3
answers
265
views
Search requests with multiple search values
(related: Fetching records matching multiple joined attributes)
If Spring Data doesn't allow GET requests to have a body (and it's considered bad practice anyway)
curl -X 'GET' \
'http://localhost:...
0
votes
2
answers
156
views
Is it better to pass a specific “context” object to handlers rather than the entire domain object?
I’m designing a system where various “handlers” apply business rules to an object. Initially I had each handler receive the full domain object:
// A large domain object with many properties and ...
1
vote
5
answers
557
views
Code reusability/inheritance introduces pointless testing
Say I have a bunch of classes that imitate cars: SportsCar, Truck, and SUV. All of these classes share some public methods like start() and stop() which they inherit from an abstract class Car. While ...
2
votes
2
answers
242
views
Best way to add asynchronous execution for already implemented synchronous process
I have a complex process implemented in Java Spring microservice.
Currently this process is triggered on user request and it is synchronously executed.
This often results in a gateway timeout.
...
2
votes
3
answers
181
views
Domain data classes with fluid property lists
Is it fine for your data models to have a sort of "open-ended" list of properties?
For example, you may have some Employee:
// getters, setters, annotations are omitted
public class Employee ...
0
votes
1
answer
219
views
How should ViewModels and Services communicate in a JavaFX + Spring Boot MVVM application?
I'm building a JavaFX + Spring Boot application using the MVVM pattern.
I’m building a generic “wizard” in a JavaFX + Spring Boot MVVM app. A WizardViewModel drives a sequence of steps (STEP_ONE → ...
21
votes
5
answers
5k
views
Why should I never ever ever use Java serialization?
I've heard that I should never use Java serialization (Serializable/ObjectInputStream/ObjectOutputStream) because of security. What's the problem?
2
votes
3
answers
445
views
Naming convention for boolean returning methods
There's a convention for boolean property accessors to name them like isX().
Does it apply to all boolean returning methods that are not invoked for their useful side effects, like this one?
Also, ...
3
votes
2
answers
495
views
Why do I need an authorisation server if my micro services can validate JWTs directly?
I'm working on a Spring-based micro service project and considering different approaches for handling authentication and authorization. Instead of setting up a dedicated authorization server, I'm ...
-1
votes
1
answer
328
views
Pattern for a chain of unreliable steps
I would like to refactor some code of a process that must perform a processing. The processing involves several steps, each of which can fail or go well. If successful, it must proceed to the next ...
8
votes
7
answers
5k
views
Must getters return values as is?
We have entities with numeric properties, they are of boxed types (e.g. Integer). Typically, each of those properties has a pair of getters: getInt(), which returns zero on null values, and ...
1
vote
2
answers
379
views
I'm confused how to structure my pom.xml when both Parent and Child modules are being developed simultaneously
Let's say I have the following maven projects.
UtilsLibrary -- A maven project containing utils.
AppA -- A maven project that depends on UtilsLibrary.
AppB -- A maven project that depends on ...
1
vote
4
answers
209
views
Ensuring type safety, honoring supertype contract
Due to type erasure, I can't do instanceof T in Java. With that in mind, how do (should) I write, for example, a generic TreeNode (or, more precisely, DefaultMutableTreeNode)? setUserObject() accepts ...
5
votes
5
answers
975
views
Handling class specific behavior: polymorphism vs instanceof
I'm designing a system with different types of components, and I'm trying to decide whether to use polymorphism or instanceof checks for handling type-specific behavior.
I see two possible approaches:
...
0
votes
2
answers
364
views
Which is better: a chain of OR statements or IF in a loop? (Java)
Which code style is preferred in Java?
final boolean result = isCausedBy(e, ExceptionType1.class)
|| isCausedBy(e, ExceptionType2.class)
|| isCausedBy(e, ExceptionType3.class)
|...
5
votes
4
answers
350
views
Ugly nested parameterizations
Suppose there's a long IO operation that may result in some return value — but doesn't have to. Completion with no return value is different from the operation being pending.
Do I have better options ...
3
votes
1
answer
168
views
Deciding on granularity of SOLID's SRP
I am currently working in a project where we are utilizing kafka as a Message Queue. We have two use cases here, one is to consume the messages in parallel, no ordering of any kind required. And one ...
4
votes
4
answers
460
views
Documenting properties
Suppose I have a property with an associated getter and setter (the property is not exposed directly)
Where should I describe the property?
The field javadoc
The getter javadoc
The setter javadoc
...
3
votes
4
answers
2k
views
Avoiding instanceofs with GUI composites
I have a stack of custom Row widgets. Each of them is a label with some editComponent (often a JTextComponent). Rows are aware of their previous and next siblings (if a Row has no such sibling, the ...
4
votes
3
answers
872
views
Clearing static state before testing each method
My SUT class depends on external static state (which generally should be avoided, I know).
How do I make sure my tests do not depend on their order of execution?
I mean other by introducing some reset(...
0
votes
2
answers
242
views
Is Spring Boot Unit Test Coverage with Integration tests only a bad practice?
I have recently come across a few codebases at work where the previous developers chose to reach the >80% coverage criteria by writing only integration tests with the @SpringBootTest annotation ...
3
votes
3
answers
546
views
How to handle checked exceptions on interface contract in Java
I am starting a project in Java and ran into the following situation. The application requires a persistence layer for a certain document type. This could be a MySql database, an AWS Dynamo DB ...
0
votes
1
answer
86
views
Versioning for a set of plugin libraries that supports foundational concepts within various toolsets
I have a foundational metamodel which I have implemented using Java interfaces which I can easily version using major.minor.bugfix.
I also have plugins that utilize these libraries to implement these ...
1
vote
4
answers
546
views
Combining multiple input validations into one exception
In order to make sure methods fail fast under invalid arguments, I usually do validation at the start of a method. If I'm verifying multiple predicates, this leads to a few lines of checkNotNull or ...
0
votes
2
answers
193
views
How to minimize the issues when SQL PreparedStatement is not an option
The application in question is integrating with BigImportantThing (BIT). Part of our application's job is to provide a better interface, so this is something to resolve within our application. The ...
1
vote
1
answer
97
views
Handling order Id In OMS system on application level [closed]
Situation: Order Handling in OMS System: In my OMS system, orders are pushed from an online platform with a unique orderId.
Since the orderId is generated by the online platform, I cannot make it auto-...
0
votes
0
answers
93
views
Disable tenants in multi tenant SaaS app
I am building an app where I have tenants and each tenant can have multiple users. The users can do multiple things in the application and these functionalities also are kind of independent from each ...
2
votes
0
answers
150
views
When Should We Separate DTOs from REST API Serialization Classes? [closed]
We know that combining a domain entity, a DTO, and a REST API serialization class into one won't pass code review:
@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
@Builder
@Entity
@Table(name = "...
3
votes
3
answers
1k
views
Should business logic classes be POJO only?
I read about three-tier architecture and I have a question: I read that in business logic (that is, what is in logic tier) there should be POJO classes, but in most Spring manuals these classes are ...
0
votes
1
answer
180
views
Feasibility of using different java version for different project with different compatibility properties
I have multiple Flutter Android app projects that have different compatibilities of Java.
Now, what should I do if I am developing more than one project simultaneously?
If the first one uses Java 17, ...
4
votes
5
answers
3k
views
The best way to handle exceptions?
I have the following method, which needs to return a List, but exceptions might occur along the way, and I don't want to handle them in my application, mainly because I don't even know how to handle ...
0
votes
2
answers
604
views
How does the MVC pattern actually work?
I’m still a Computer Science student, and recently I’ve had to develop a project using the MVC pattern, but without having learned in depth about how it actually works. And it’s not the first time I’...
2
votes
1
answer
243
views
checkNotNull vs. JEP 358: Helpful NullPointerExceptions: Should we remove existing null checks?
With the introduction of JEP 358 in Java 14, which provides more informative NullPointerException (NPE) messages, is it advisable to remove existing explicit null checks in cases where the null-check ...
2
votes
3
answers
998
views
Is breaking encapsulation a necessary compromise for serialization?
I've been considering the way to solve this problem for a while, and I'm currently stuck between two options I both feel are suboptimal. Here's an abstract example of what I'm dealing with:
I have a ...
-2
votes
1
answer
221
views
Vanilla interface implementations. What should I call it? [closed]
Some may think I'm kidding, but I'm really stuck on this
Suppose you have some UserDao interface that you want to implement
What should you call it?
Here are a few points I'd like to make
I firmly ...
1
vote
2
answers
346
views
How modern runtimes handle both interpreted and JITted code at the same time?
I have a personal project, I want to write a JIT compiler/runtime in Rust (well, the language is not that relevant). I'm thinking about using a technique where the code is interpreted first and then ...
0
votes
2
answers
316
views
DDD: How to update a domain model with a lot of fields
Let's say there is a domain model:
@Table(name = "room")
@Getter
@FieldNameConstants
@AllArgsConstructor(onConstructor = @__({@PersistenceCreator}))
public class HotelRoom extends ...
2
votes
2
answers
294
views
In Java Interface contracts, does the @throws tag order should be considered?
Concrete example : https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/DataInput.html#readFully(byte[],int,int)
@throws NullPointerException if {@code b} is {@code null}.
is before
@...