Skip to main content

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.

Filter by
Sorted by
Tagged with
1 vote
4 answers
170 views

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 ...
Conquer the world's user avatar
2 votes
3 answers
660 views

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 ...
Sergey Zolotarev's user avatar
7 votes
3 answers
551 views

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 ...
Ellen Spertus's user avatar
1 vote
1 answer
236 views

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'...
Ice K's user avatar
  • 31
1 vote
2 answers
260 views

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 ...
Sergey Zolotarev's user avatar
0 votes
2 answers
204 views

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 ...
Ryley38's user avatar
  • 111
0 votes
2 answers
146 views

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?...
A. WW's user avatar
  • 11
21 votes
5 answers
5k views

I've heard that I should never use Java serialization (Serializable/ObjectInputStream/ObjectOutputStream) because of security. What's the problem?
Stack Exchange Broke The Law's user avatar
23 votes
9 answers
7k views

I'm taking another crack at learning Java with the aim of getting a job. As I write code, I sometimes find it quite difficult to navigate my code using the formatting I often see in tutorials. ...
KanagawaPunk's user avatar
8 votes
7 answers
5k views

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 ...
Sergey Zolotarev's user avatar
4 votes
2 answers
330 views

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 ...
User1254's user avatar
3 votes
2 answers
512 views

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 ...
GeekChap's user avatar
1 vote
5 answers
561 views

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 ...
Ruben Rundström's user avatar
2 votes
3 answers
271 views

(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:...
Sergey Zolotarev's user avatar
0 votes
3 answers
221 views

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 ...
Sergey Zolotarev's user avatar
-1 votes
1 answer
328 views

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 ...
jordan1982's user avatar
389 votes
35 answers
640k views

As a professional Java programmer, I've been trying to understand - why the hate toward Java for modern web applications? I've noticed a trend that out of modern day web startups, a relatively small ...
5 votes
5 answers
977 views

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: ...
user avatar
1 vote
2 answers
208 views

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 ...
Sergey Zolotarev's user avatar
3 votes
4 answers
2k views

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 ...
Sergey Zolotarev's user avatar
311 votes
14 answers
485k views

I am working on a java project. I am new to unit testing. What is the best way to unit test private methods in java classes?
Vinoth Kumar C M's user avatar
277 votes
14 answers
126k views

I was told by a colleague that in Java object creation is the most expensive operation you could perform. So I can only conclude to create as few objects as possible. This seems somewhat to defeat ...
Slamice's user avatar
  • 2,667
4 votes
5 answers
3k views

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 ...
MasterTJ123's user avatar
4 votes
4 answers
462 views

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 ...
Sergey Zolotarev's user avatar
8 votes
5 answers
4k views

Suppose I have a constructor that performs an expensive IO operation that takes a noticeable amount of time. I don't like it for a few reasons (first of all, it's simply wrong, but there are practical ...
Sergey Zolotarev's user avatar
11 votes
7 answers
5k views

There is a dependency jar containing tons of service classes mostly used to retrieve data from database, and this jar is used among several different micro services in one cluster. There is a big ...
Rui's user avatar
  • 1,935
0 votes
2 answers
160 views

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 ...
nicke7117's user avatar
2 votes
3 answers
451 views

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, ...
Sergey Zolotarev's user avatar
296 votes
16 answers
30k views

I used to code in Python a lot. Now, for work reasons, I code in Java. The projects I do are rather small, and possibly Python would work better, but there are valid non-engineering reasons to use ...
Mikhail Ramendik's user avatar
0 votes
1 answer
132 views

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-...
Apollo's user avatar
  • 139
0 votes
1 answer
222 views

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 → ...
Billie's user avatar
  • 77
9 votes
5 answers
6k views

I'm in my intro classes and trying to understand how a Java compiler works. Most posts said a compiler translates A to B (which could be machine code) to run, while an interpreter 'just' runs the code....
miiky123's user avatar
  • 241
119 votes
12 answers
20k views

The codebase I'm working on frequently uses instance variables to share data between various trivial methods. The original developer is adamant that this adheres to the best practices stated in the ...
Alexander's user avatar
  • 1,083
2 votes
2 answers
251 views

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. ...
DimitrijeCiric's user avatar
19 votes
6 answers
9k views

I'm currently writing an MVC application and I need a class that can: A: get, add and remove data(specifically a TreeSet of sorted strings that I want stored in memory, but I doubt the data itself is ...
Tyler Del Rosario's user avatar
5 votes
4 answers
353 views

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 ...
Sergey Zolotarev's user avatar
106 votes
11 answers
17k views

I hate referencing paywalled content, but this video shows exactly what I'm talking about. Precisely 12 minutes in Robert Martin looks at this: And says "One of my favorite things to do is getting rid ...
candied_orange's user avatar
23 votes
5 answers
18k views

I consider Joshua Bloch's Effective Java the best book on the language that I read. However, I started to wonder about something One of the things he suggested was to prefer public static factory ...
demavi's user avatar
  • 347
7 votes
9 answers
8k views

According to one definition of "interface segregation principle" that states currently in Two contradicting definitions of Interface Segregation Principle – which one is correct?, a client ...
wcminipgasker2023's user avatar
61 votes
11 answers
15k views

This Stack Overflow post lists a fairly comprehensive list of situations where the C/C++ language specification declares as to be 'undefined behaviour'. However, I want to understand why other modern ...
Sisir's user avatar
  • 898
3 votes
3 answers
554 views

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 ...
Matias Grioni's user avatar
1 vote
4 answers
211 views

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 ...
Sergey Zolotarev's user avatar
0 votes
1 answer
116 views

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) ...
GeekChap's user avatar
196 votes
40 answers
21k views

So my Dad bought me 5 books on programming (C++, Java, PHP, Javascript, Android) about a month ago. He's an architect and he knows NOTHING about programming. He bought me them because I told him ...
2 votes
3 answers
182 views

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 ...
Sergey Zolotarev's user avatar
14 votes
5 answers
5k views

According to Explanation on how "Tell, Don't Ask" is considered good OO, I know the following is bad: if(a.isX){ a.doY(); } public class A{ public boolean isX; public void ...
wcminipgasker2023's user avatar
1 vote
2 answers
252 views

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 ...
Mary's user avatar
  • 13
2 votes
3 answers
1k views

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 ...
pulpicated's user avatar
6 votes
5 answers
841 views

Suppose, I have some method that performs some job. In this example, it's going to be void, but it doesn't matter public void doSomething() { // doing something } But then, let's imagine, I got ...
Sergey Zolotarev's user avatar
4 votes
3 answers
909 views

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(...
Sergey Zolotarev's user avatar

1
2 3 4 5
101